(Same C code as before, but now:) Line 1 is replaced by `auto int a = 1;` and Line 2 is replaced by `register int a = 2;`. What output will be generated by the given code segment now? (rows show successive printf outputs)
- A3 1 / 4 1 / 4 2
- B4 2 / 6 1 / 6 1
- C4 2 / 6 2 / 2 0
- 4 2 / 4 2 / 2 0
Explanation
`register` behaves like a plain automatic (non-static) variable — prtFun's a is now reinitialized to 2 on EVERY call, not retained. Call 1: a=2, b:1→2, a=2+2=4 → '4 2'. Call 2: a reinitializes to 2 again, b:1→2, a=2+2=4 → '4 2' again (no persistence this time). main's own a is now plain auto (behaviorally unchanged since main runs once), and global b is still untouched (0) → final print '2 0'. Full output: 4 2 / 4 2 / 2 0.
Source: GATE CS 2012 (2012)
This question is part of a 15-day revision cycle — sign in and Project Forge will bring it back the day before you'd forget it.