Consider the following C program: #include <stdio.h> #define EOF -1 void…
GATE · 2007 · ITModified — slightly modified from the official paper; see the solution
Consider the following C program:
#include <stdio.h>
#define EOF -1
void push(int); /* push the argument on the stack */
int pop(void); /* pop the top of the stack */
void flagError();
int main()
{
int c, m, n, r;
while ((c = getchar()) != EOF)
{
if (isdigit(c))
push(c - '0');
else if ((c == '+') || (c == '*'))
{
m = pop();
n = pop();
r = (c == '+') ? n+m : n*m;
push(r);
}
else if (c != ' ')
flagError();
}
printf("%d", pop());
}What is the output of the program for the following input?
5 2 * 3 3 2 + * +- A.
15
- B.
25
- C.
30
- D.
150
Attempted by 476 students.
Show answer
Correct answer: B
Explore the full course: Iocl Engineers Officers Grade A Paper 2
Loading lesson…