Have I labeled the below code properly using the terms precedence, identifier scope, variable lifetime, global scope, and local scopes? #include using namespace std; // Global Scope const int x = 10; // Global Scope int printx(int b); //global scope int main() { cout << "Before local declaration in main, x = " << x << endl; int x = 15; // local scope; prevents access to global x w/ name presedence cout << "After local declaration in main, x = " << x << endl; int a = printx(x); // local scope cout << "After function call complete, x = " << x << endl; x = a; // local scope cout << "After assignment in main complete, x = " << x << endl; return 0; } int printx(int b) { cout << "Before local declaration in function, x = " << x << endl; b = 20; // local scope; uses name presedence int x = b; // local scope cout << "After local declaration in function, x = " << x << endl; return x; }
Have I labeled the below code properly using the terms precedence, identifier scope, variable lifetime, global scope, and local scopes?
#include <iostream>
using namespace std; // Global Scope
const int x = 10; // Global Scope
int printx(int b); //global scope
int main()
{
cout << "Before local declaration in main, x = " << x << endl;
int x = 15; // local scope; prevents access to global x w/ name presedence
cout << "After local declaration in main, x = " << x << endl;
int a = printx(x); // local scope
cout << "After function call complete, x = " << x << endl;
x = a; // local scope
cout << "After assignment in main complete, x = " << x << endl;
return 0;
}
int printx(int b)
{
cout << "Before local declaration in function, x = " << x << endl;
b = 20; // local scope; uses name presedence
int x = b; // local scope
cout << "After local declaration in function, x = " << x << endl;
return x;
}
Step by step
Solved in 3 steps with 1 images