Question

Let the function fun be defined as int fun(int *k) { *k - = 2; return...

Let the function fun be defined as
int fun(int *k) {
*k - = 2;
return 4 * (*k) +2 ;
}
Suppose fun is used in a program as follows:
void main() {
int i = 16, j = 16, sum1, sum2;
sum1 = (i / 2) + fun(&i);
sum2 = fun(&j) + (j / 2);
}
What is the values of sum1 and sum2
a. If the operands in the expressions are evaluated from left to right
sum1 = sum2 =
b. If the operands in the expressions are evaluated from right to left
sum1 = sum2 =

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for the question.
Here is the completed code for this problem. Let me know if you have any doubts or if you need anything to change.
Thank You !!
================================================================================================

a. If the operands in the expressions are evaluated from left to right
sum 1 will be : 66

first i/2 will be evaluated 16/2 = 8
fun(&i) = 4*14+2 = 58
so sum1 will be 8+58 = 66

sum 2 will be : 65
first fun(&j) will be evaluated which is equal to 4*14+2 = 58 and in this step j is reduced to 14
then j/2 will be evaluated which is equal to 14/2 = 7
so sum2 will be 58+7=65

===========================================================================================

b. If the operands in the expressions are evaluated from right to left

sum 1 will be : 65

first fun(&i) will be evaluated which is equal to 4*14+2 = 58 and in this step i is reduced to 14
then i/2 will be evaluated which is equal to 14/2 = 7
so sum1 will be 58+7=65

sum 2 will be : 66

first j/2 will be evaluated 16/2 = 8
fun(&j) = 4*14+2 = 58
so sum2 will be 8+58 = 66
=====================================================================================

Add a comment
Know the answer?
Add Answer to:
Let the function fun be defined as int fun(int *k) { *k - = 2; return...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT