Question: 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

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 Programming Questions!