Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

int fun(int *n) { *n /= 5; return -50; } void main() { int num = 25; num = num *

ID: 3706319 • Letter: I

Question


int fun(int *n) { *n /= 5; return -50; }
void main() { int num = 25; num = num * fun(&num); }

What is the value of num after the assignment statement in main, assuming: A) Operands are evaluated from left to right:
B) Operands are evaluated from right to left:

Please explain this with correct answers.
int fun(int *n) { *n /= 5; return -50; }
void main() { int num = 25; num = num * fun(&num); }

What is the value of num after the assignment statement in main, assuming: A) Operands are evaluated from left to right:
B) Operands are evaluated from right to left:

Please explain this with correct answers.
int fun(int *n) { *n /= 5; return -50; }
void main() { int num = 25; num = num * fun(&num); }

What is the value of num after the assignment statement in main, assuming: A) Operands are evaluated from left to right:
B) Operands are evaluated from right to left:

Please explain this with correct answers.

Explanation / Answer

A) when operands are evaluated from left to right:

initially num = 25; i.e int num = 25;

then next statement is => num = num * fun(&num);

since operands are evaluated from left to right hence

num = 25 * fun(&num)

and then in function fun num is changes to num / 5 i.e num = 5 and after changing value of num function return value -50 to main function call

num = 25 * (-50)

and hence final value of num = -1250

B) when operands are evaluated from right to left:

int num = 25;   i.e currently num = 25

num = num * fun(&num); i.e

num = num * fun(&num); i.e right operand evaluated first in this case it is a function call

int fun(int *n)

{

*n /= 5; //this will set num = 25 / 5 = 5

return -50; //and this will return -50 to called function

}

i.e

num = num * (-50); //since previous function call has also changed the value of num to 5, hence

num = 5 * (-50)

num = - 250

hence final value of num is -250 in this case

NOTE: Evaluate expression one by one and assign value accordingly whether it is evaluated from right to left or left to right