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)
|
|||||||
|
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... |
Name | Discussion |
---|