Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone add in-line comments to this C code? I'm not 100% sure how it works. #include int eval (char operator, int x, int y)

Can someone add in-line comments to this C code? I'm not 100% sure how it works.

#include

int eval (char operator, int x, int y)

{

switch (operator)

{

case '+': return x + y;

case '-': return x - y;

case '*': return x * y;

case '/': return x / y;

}

return 0;

}

int

main ()

{

char exp[20];

printf (\"Enter the expression: \");

scanf (\"%s\", exp);

int result, operand = 0;

char *expr = exp, operator;

char ch = *expr;

result = ch - '0';

expr++;

while (*expr != '\\0')

{

char ch = *expr;

switch (ch)

{

case '0':

case '1':

case '2':

case '3':

case '4':

case '5':

case '6':

case '7':

case '8':

case '9': result = eval (operator, result, ch - '0');

break;

case '+': operator = '+';

break;

case '-': operator = '-';

break;

case '*': operator = '*';

break;

case '/': operator = '/';

break;

}

expr++;

}

printf (\"The result of strict L->R evaluation is: %d \", result);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions

Question

Solve the inequality 3 4x > 5. Graph the solution set.

Answered: 1 week ago

Question

What is the logit transformation for a probability ?????

Answered: 1 week ago