- 1

{int a=1; printf("%d",++a); func(); printf("%d",++a); return 0;} void func(){int a=10; return 1;}

Why is output 23??

10th May 2020, 3:22 PM
Karan Dewangan
Karan Dewangan - avatar
2 odpowiedzi
+ 2
The function works on a copy of a, not the actual a from main. Does it make more sense now?
10th May 2020, 3:24 PM
HonFu
HonFu - avatar
+ 1
Your 'void func()' is playing no role in the code in your main(). How come a void function return something? It is just the 'a' in main() printed twice after incrementing each time.
10th May 2020, 4:23 PM
Avinesh
Avinesh - avatar