Please explain. Thanks! 10.) What prints as a result of the following program ex
ID: 3860769 • Letter: P
Question
Please explain. Thanks!
10.) What prints as a result of the following program execution? Put the outputs in the correct order in which they would occur. Be sure to start at main!
int x; // global
void doLocal()
{
int x =12;
cout << “x = “ << x << endl;
}
void doGlobal()
{
x = 20 ;
cout << “x = “ << x << endl;
}
void doValue(int a)
{
a = 4 ;
cout << “a = “ << a << endl;
}
void doReference(int& a)
{
a = 3 ;
cout << “a = “ << a << endl;
}
int main ()
{
x = 25 ;
doLocal() ;
cout << “x = “ << x << endl;
x = 35 ;
doGlobal() ;
cout << “x = “ << x << endl;
x = 30 ;
doValue(x) ;
cout << “x = “ << x << endl;
x = 45 ;
doReference(x) ;
cout << “x = “ << x << endl;
return 0 ;
}
Explanation / Answer
12
25
20
20
4
30
3
3
These are the output for the current program.
it print 12 because it is local variable
it print 25 because it is the value of global x
it print 20 because it is local variable