•• R5.9We have seen three kinds of variables in C++: global variables, parameter variables, and local variables. Classify the variables of Exercise •• R5.8 according to these categories.
1 int a = 0;
2 int b = 0;
3 int f(int c)
4 {
5 int n = 0;
6 a = c;
7 if (n < c)
8 {
9 n = a + b;
10 }
11 return n;
12 }
13
14 int g(int c)
15 {
16 int n = 0;
17 int a = c;
18 if (n < f(c))
19 {
20 n = a + b;
21 }
22 return n;
23 }
24
25 int main()
26 {
27 int i = 1;
28 int b = g(i);
29 cout << a + b + i << endl;
30 return 0;
1 int a = 0; // global variables
2 int b = 0; // global variables
3 int f(int c) // here c is parameter
4 {
5 int n = 0; // c is local variable
6 a = c; // here a is global variable
7 if (n < c)
8 {
9 n = a + b; // a,b are global variable
10 }
11 return n;
12 }
13
14 int g(int c) // here the c is parameter
15 {
16 int n = 0; // here n is local variable
17 int a = c; // here a is local variable
18 if (n < f(c))
19 {
20 n = a + b; // here a is local variable and b is global variable
21 }
22 return n;
23 }
24
25 int main()
26 {
27 int i = 1; // here i is local variable
28 int b = g(i); // here b is local variable
29 cout << a + b + i << endl; // a,b is global variable
30 return 0;
Get Answers For Free
Most questions answered within 1 hours.