wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

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 flag Error( );
int main ( )
{
int c, m, n, r;
while ((c = getchar ( ))! = EOF)
{
if (isdigit (c))
push (c);
else if ((c = = '+') | | (c = = '*'))
{
m = pop ( );
n = pop ( );
r = (c = = '+') n + m : n*m;
push (r);
}
else if ( c! = ' ')
flag Error ( );
}
printf("%c", pop( ));
}

What is the output of the program for the following input?

5 2 * 3 3 2 + * +

A
25
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
B
150
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
30
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
15
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is A 25
push 5
push 2
push 5*2 = 10 (pop 5 and 2)
push 3
push 3
push 2
push 3 + 2 = 5 (pop 2 and 3)
push 5 * 3 =15 (pop 5 and 3)
push 15 + 10 = 25 (pop 15 and 10)

flag
Suggest Corrections
thumbs-up
1
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Solving Inequalities
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon