🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Storage Classes in C: all 15 questions

Quiz: Storage Classes in C · Question 6 of 15

What does this print? (code)

What does this print?

#include <stdio.h>
int n = 10;
int main(void) {
    int n = 20;
    {
        n = n + 5;
        int n = 1;
        printf("%d ", n);
    }
    printf("%d", n);
    return 0;
}
  1. A.1 10
  2. B.25 25
  3. C.1 25
  4. D.1 20
Answer & explanation

Correct answer: 1 25

n = n + 5 runs before the inner n exists, so it changes the local n to 25. Then the inner n (1) is printed, and after the block the local n (25).

Can you get the rest right without peeking?

Take the timed Quiz: Storage Classes in C quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →