← 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;
}
- A.3 2 1
- B.3 4 2
- C.1 4 2
- 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 →