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; }

17th Jan 2019, 12:27 AM
Waleid Al-Shhadat
1 Odpowiedź
+ 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
17th Jan 2019, 7:51 AM
Hardik Sharma
Hardik Sharma - avatar