Question

Consider the following C program: int sub(int *sum) { *sum =*sum +*sum; return 10; } void...

Consider the following C program:

int sub(int *sum)

{ *sum =*sum +*sum;

return 10; }

void main() {

int num= 3;

num = sub(&num)+ num;

}

What is the value of num after the assignment statement in main, assuming

operands are evaluated left to right.

operands are evaluated right to left.

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

by function definition :

int sub(int *sum)

{ *sum =*sum +*sum;

return 10; }

we see that whatever value we pass to this function, it will return 10 irrespective of the value of sum.

main function:

void main() {

int num= 3;

num = sub(&num) + num;

}

value of num

will be value returned by sub function + num

num is initialised by 3

so as we have seen sub function will return 10 and value of num is 3

so statement is

10 + 3

operands are evaluated left to right.

operands are evaluated right to left.

these will not make any difference as there is only one operator and value calculated from left to right or right to left will be same.

so answer for given problem for both the cases will be : 13.

Hope this helps!
Kindly appreciate the help by upvoting the answer. Thank you!

Add a comment
Know the answer?
Add Answer to:
Consider the following C program: int sub(int *sum) { *sum =*sum +*sum; return 10; } void...
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
Active Questions
ADVERTISEMENT