Skip to content
Related Articles

Related Articles

C | Storage Classes and Type Qualifiers | Question 14
  • Difficulty Level : Easy
  • Last Updated : 26 Feb, 2013

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: (D)

Explanation: 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 won’t change anything in output.

Please write comments if you find any of the answers/explanations incorrect, or you want to share more information about the topics discussed above.

Quiz of this Question

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
My Personal Notes arrow_drop_up
Recommended Articles
Page :