C - Data Types - Discussion

You Are Here :: Home > C > Data Types - Discussion

 



Q.

What output will be generated by the given code d\segment if:

Line 1 is replaced by "auto int a = 1;"
Line 2 is replaced by "register int a = 2;" (GATE CS 2012)

A. 3 1
4 1
4 2
B. 4 2
6 1
6 1
C. 4 2
6 2
2 0
D. 4 2
4 2
2 0

Answer: Option D
Explaination:

If we replace line 1 by "auto int a = 1;" and line 2 by "register int a = 2;", then 'a' becomes non-static in prtFun(). The output of first prtFun() remains same. But, the output of second prtFun() call is changed as a new instance of 'a' is created in second call. So "4 2" is printed again. Finally, the printf() in main will print "2 0". Making 'a' a register variable wo't change anything in output.



Discussion

Your Comments Goes here...
NameDiscussion