Multiple choice

What output will be generated by the given code segment if: Line 1 is replaced by auto int a = 1; Line 2 is replaced by register int a = 2;

  1. 3 1 4 1 4 2

  2. 4 2 6 1 6 1

  3. 4 2 6 2 2 0

  4. 4 2 4 2 2 0

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Static local variables: Scope is limited to function/block but life time is entire program. Automatic local variables: Storage allocated on function entry and automatically deleted or freed when the function is exited. Register variables: Same as automatic variables except that the register variables will not have addresses. Hence, may not take the address of a register variable.