edited by
2,385 views

8 Answers

1 votes
1 votes

correct Answer is option D

 x=y++ + x++; ----------- statement1

first calculation will be done then incrementation will happen so

x= 20+35

then due to post-increment that is  x++ and y++, the value of x will be 56 and y will be 36

 y=++y + ++x; -----------statement 2

now due to pre-increment that is ++x and ++y, the value of x will be 57 and y will be 37

y=57+37

then after executing the statement 2  value of y will become 94

so x is 57 and y is 94

 

1 votes
1 votes
The Answer is Option D

Explanation:

As x = 20, y = 35;

So x = y++ + x++; // as the expression of y and x are post increment so first their will be addition of y + x and then it will do the work of increment of x and y var.

x = 56  and y = 36

Now for y = ++y + ++x; // here the incrementing is done first then addition of x and y expression

y = 94

Therefore, x = 57, y = 94
0 votes
0 votes
Initial value of x and y are 20, 35 respectively.

Now, in next expression, x and y both are getting post incremented and assigned to x.

So, as you might be knowing that whenever there is an post increment it will first get assigned and then it will get incremented.

So, as it's a '+' operator and it's left associative.

x++ will be first assigned 20 and y++ will be 35. And both will get added and assigned to x. So, now x will be 55 and y will be 36. Now, as y was post incremented it will increment after assignment same x also will get incremented but as at last 55 will get assigned to x.

So, after 1st expression x will be 55, y will be 36.

2nd expression is having addition of 2 pre increment. ++x will be 56 and ++y will be 37 and addition of both will be 93.

So, final answer will have x=56, y=93.

Correct option is not given. For confirmation I have also ran this program on online C compiler and it's also giving me same answer.

Related questions

1 votes
1 votes
2 answers
1
go_editor asked Mar 26, 2020
1,534 views
After $3$ calls of the $c$ function bug ( ) below, the values of $i$ and $j$ will be :int j = 1; bug () { static int i = 0; int j = 0; i++; j++; return (i); }$i = 0, j = ...
3 votes
3 votes
2 answers
2