1 #include <iostream> 2 using std::cout; 3 4 int x = 10; 5 6 int function () 7 {
ID: 3862181 • Letter: 1
Question
1 #include <iostream> 2 using std::cout; 3 4 int x = 10; 5 6 int function () 7 { 8 x=x/2; 9 return x; 10 } 11 12 int otherFunction ( int x ) 13 { 14 int y = function() 2; 15 x=xx; 16 return x/y; 17 } 18 19 int main() 20 { 21 x=2; 22 int x = 4; 23 cout << otherFunction ( x ) << ' ' ; 24 } The code above is correct, compilable and runnable C++ code. Using the code above, answer the following questions. 1) On line 21, which x is in scope? a. It isn't in scope at all. b. The one from line 22. c. The one from line 4. d. The one from line 15. 2) On line 8, which x is in scope? a. It isn't in scope at all. b. The one from line 22. c. The one from line 21. d. The one from line 4. 3) On line 15, which x is in scope? a. The one from line 4. b. The one from line 12. c. The one from line 21. d. The one from line 22.
Explanation / Answer
1)Ans)c
We already declared the variable x as global variable and assigned 10 to it.
Here at line 21 we are assigning the value 2 to that global variable
2)Ans)c
As we didn’t declared any variable x inside the function.so here x inside the function refers to the global variable.Now the value of global variables x=2 which is referring at the line 21
3)Ans)d
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.