Multiple choice

What is the output of the following program? #include<iostream.h> static int j=10; void value() { static int j=40; cout<< now= <<j<< , ; } void value() { static int j=5; value(); cout<< next= <<j; }

  1. now = 5, next = 5

  2. now = 40, next = 5

  3. now = 10, next =10

  4. now = 40, next = 10

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

The inner value() function has static int j=40, so it prints 40. The outer value() function has static int j=5. When value() calls value(), the inner function's j (40) is printed first, then the outer's j (5). The global j=10 is shadowed by both function-local static variables.