Question: How to implement this option in my following code One ternary operation ?: The usual ternary expression a ? b : c in C will

How to implement this option in my following code

One ternary operation ?: The usual ternary expression a ? b : c in C will be written as c b a ?. If a is non-zero, the value of the expression is b, otherwise it is c.

#include #include #include #include "calc.h"

#define MAXOP 128

int main(int argc, char *argv[]) { int type; int op2; char s[MAXOP];

while ((type = getop(s)) != EOF) { switch(type) {

/*made the atoi change*/ case NUMBER: push(atoi(s)); break; case '+': push((int)pop() +(int)pop()); break; case '-': op2 = pop(); push((int)pop() - (int) op2); break; case '*': push((int)pop() *(int)pop()); break; case '/': op2 = pop(); if (op2 != 0.0) push((int)pop() / (int)op2); else { printf("error : zero divisor ");

case '&': push((int)pop() & (int) pop()); break;

case '|': push((int)pop() | (int) pop()); break;

case '^': push((int)pop() ^(int) pop()); break; /* Bitwise not operation */

case '~': { int a = pop(); a = ~a; push(a); break; } /*Returns 1 for true and 0 for false*/ case '>': push((int) pop() >(int) pop()); break;

case '=': push((int)(pop() == (int) pop())); break;

case '<': push((int)pop() < (int)pop()); break;

/*returns 1 if number is 0 otherwise 1*/ case '!': push((int)pop() == 0); break;

case ' ': printf(" The answer is %d ", pop()); break; default: printf("error: unknown command %s ", s); exit(1);

}

} } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!