1,559 views
1 1 vote

What will be the output?

1 Answer

Best answer
1 1 vote

1) int a,b; ---- a,b are global variables ===> initialized by their default values ==> a=0, b=0. but note that main have variable a, therefore it can't access global a but it can access global b, coming to function f() it have variable a and variable b in it's function as local variables, therefore it can not access either global a or global b

2) void f(); ---- declaring f is a function which accepts no parameters(not compulsory) and no return type

3) int main()

4) {

5)          static int a=1; ----> static variable, for avoiding confusion, name it as main.a=1

6)         f(); ------------> Calling function f()

goto 11th line, creating and initializing f.a=2, f.b=2, f.a value updated as 4 in 15th line, after execution of 15th line f.b updated as 3

by 16th line printing 4,3

by 17th line, f.b is removed but f.a is still in static memory with the value 4

7)         a*=2; ===> a=a*(2) -----> main.a = main.a*(2) ===> main.a updated to 2

8)         f();  ------------> Calling function f()

goto 11th line, creating f.b=2 only, already f.a created and  f.a value is 4. f.a value updated as 8 in 15th line, after execution of 15th line f.b updated as 3

by 16th line printing 8,3

by 17th line, f.b is removed but f.a is still in static memory with the value 8

9)         printf("%d..%d",a,b); ----> accessing main.a, global.b ===> print 2,0

10) }

11) void f()

12) {

13)         static int a=2;

14)         int b=2;

15)          a*=b++; ====> a=a*(b++);

16)         printf("%d..%d",a,b);

17)  }

selected by
Position:
Show:

No related questions found