0
Hello , what is the output in this code and why ?
#include <iostream> using namespace std; int g =10 ; void fun () { g= 5 ; return ; } int main() { ::g = 15 ; fun(); cout << ::g << endl ; return 0; }
1 Réponse
+ 1
The code should print '5'
The concept over here is global variables.
Let's start with main function
::g = 15; -- This will change the value to 15
Then you called the function fun() which changes the value of g to 5
In the next line you have printed the global variable g, the value is 5