What is the output of the following C++ program? #include <iostream.h> int x=7; void showx (); void showxagain (); void main() { showx (); showx (); showxagain (); showxagain (); } void showx () { int x=34; cout << x++ << endl; } void showxagain () { cout << x++ << endl; }
The correct option is (3): 34, 34, 7. This program demonstrates key concepts of variable scope in C++: global variables, local variables, and the post-increment operator. The global variable int x = 7; is accessible throughout the program. However, inside the showx() function, a local variable int x = 34; is declared. This local variable shadows the global variable, meaning all operations inside showx() use this local copy, leaving the…Read More
Source :
Source :
Source :
Source :