🎙 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 12 of 15

What does this print? (code)

What does this print?

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

Correct answer: 1 2

The local n in main hides the global only inside main; show() can only see the global n, which is 1.

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 →