C++: Execute the following program and identify the variables that have been cre
ID: 3810484 • Letter: C
Question
C++: Execute the following program and identify the variables that have been created but not destroyed when the cout statement in the function advertissement is executed. What is the scope of each? What is the value of each?
OUTPUT:
x = z
Hey ho, I'm from Idaho!
You gotta taste it all!
x = z
Explanation / Answer
Program:
#include <iostream>
using namespace std;
void advertisement();
void potato();
int main()
{
char x; // Here we are declaring x as char variable
x='Z'; // Here we are initializing the value of x as Z
cout<< "x= " << x<< endl; // Here we are Printing the value of x ( i.e Z )
potato(); // Here we are calling the potato() function
cout<< "x= " << x<< endl; // Here again we are Printing the value of x ( i.e Z )
return 0;
// Here in this main() function value for x=Z & scope of x is permited to this main function Only
}
void advertisement() // Here we are initializing the advertisement() function
{
char x; // Here we are declaring x as char variable
x='Y';
// Here we are initializing the value of x as Y scope of this value is permited to this function Only
cout<< x << "ou gotta taste it all! ";
}
void potato() // Here we are initializing the potato() function
{
char x; // Here we are declaring x as char variable
x='H';
// Here we are initializing the value of x as H scope of this value is permited to this function Only
cout<< x << "ey ho, I'm from Idaho! ";
advertisement(); // Here we are calling the advertisement() function
}
Output:
x= Z
Hey ho, I'm from Idaho!
You gotta taste it all!
x= Z
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.