0

[C] Why does i become 9?

int i = 10; void f(void){ int i = 5; i = 7; } void g(){ i = 9; } int main(){ i = 1; g(); f(); printf("%d", i); return 0; }

6th Dec 2021, 1:24 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
1 Answer
+ 5
int main(){ i = 1; // here i becomes 1 g(); //here i becomes 9 f(); //here the local variable i becomes 7 so the global variable i remains 9 printf("%d", i); //so here it comes 9 return 0;
6th Dec 2021, 1:46 PM
Arun Ruban SJ
Arun Ruban SJ - avatar