Consider the following C program: int fun (int *i) { *i += 5; return 4; } void m
ID: 3608235 • Letter: C
Question
Consider the following C program: int fun (int *i) { *i += 5; return 4; } void main ( ) { int x = 3; x = x + fun(& x); } What is the value of x after the assignment statement in main,assuming a. operands are evaluated left toright. b. operands are evaluated right toleft. Consider the following C program: int fun (int *i) { *i += 5; return 4; } void main ( ) { int x = 3; x = x + fun(& x); } What is the value of x after the assignment statement in main,assuming a. operands are evaluated left toright. b. operands are evaluated right toleft.Explanation / Answer
please rate - thanks What is the value of x after the assignment statement in main,assuminga. operands are evaluated left toright. 7 b. operands are evaluated right toleft. 12
left to right
int fun (int *i) { *i +=5; we add 5to x making x 8
return4; we return 4 tomain
} void main ( ) { int x = 3; x = x + fun(&x); x starts at 3 in fun it ischanged to 8 but the 3 is already being used the 4 fromfun is added (3+4) to it making it 7
}
right toleft x starts at 3 in fun x gets changed to 8 and fun is returned as 4so we have 4 + 8 = 12
to paraphrase
left to right it's is 3 + 4 =7 original value of x is used
right to left it is 4 + 8 =12 x is used as it was changed by fun, since fun was alreadyexecuted
What is the value of x after the assignment statement in main,assuming
a. operands are evaluated left toright. 7 b. operands are evaluated right toleft. 12
left to right
int fun (int *i) { *i +=5; we add 5to x making x 8
return4; we return 4 tomain
} void main ( ) { int x = 3; x = x + fun(&x); x starts at 3 in fun it ischanged to 8 but the 3 is already being used the 4 fromfun is added (3+4) to it making it 7
}
right toleft x starts at 3 in fun x gets changed to 8 and fun is returned as 4so we have 4 + 8 = 12
to paraphrase
left to right it's is 3 + 4 =7 original value of x is used
right to left it is 4 + 8 =12 x is used as it was changed by fun, since fun was alreadyexecuted
int fun (int *i) { *i +=5; we add 5to x making x 8
return4; we return 4 tomain
} void main ( ) { int x = 3; x = x + fun(&x); x starts at 3 in fun it ischanged to 8 but the 3 is already being used the 4 fromfun is added (3+4) to it making it 7
}
right toleft x starts at 3 in fun x gets changed to 8 and fun is returned as 4so we have 4 + 8 = 12
to paraphrase
left to right it's is 3 + 4 =7 original value of x is used
right to left it is 4 + 8 =12 x is used as it was changed by fun, since fun was alreadyexecuted
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.