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

Quiz: Stack and Queue in C · Question 2 of 10

What does this print? (code)

What does this print?

#include <stdio.h>
int s[10], top = -1;
void push(int x) { s[++top] = x; }
int pop(void) { return s[top--]; }
int main(void) {
    push(1); push(2); push(3);
    int a = pop();
    push(4);
    int b = pop();
    int c = pop();
    printf("%d %d %d", a, b, c);
    return 0;
}
  1. A.3 2 1
  2. B.3 4 2
  3. C.1 4 2
  4. D.3 4 1
Answer & explanation

Correct answer: 3 4 2

Pop 3, push 4, pop 4, then pop 2 (1 is still below it).

Can you get the rest right without peeking?

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

Start the quiz →