##### post incerment isro 2014

The following three 'C' language statements is equivalent to which single statement?

y=y+1; z=x+y; x=x+1

- z = x + y + 2;
- z = (x++) + (++y);
- z = (x++) + (y++);
- z = (x++) + (++y) + 1;

The following three 'C' language statements is equivalent to which single statement?

y=y+1; z=x+y; x=x+1

- z = x + y + 2;
- z = (x++) + (++y);
- z = (x++) + (y++);
- z = (x++) + (++y) + 1;

Correct answer should be 2

As y is incremented first (++y pre increment )and then the sum of x and y is assigned to z and after that assignment x is incremented (x++ post increment)

These types of question are compiler dependent but you can answer according to the general logic.

In the 2nd option

z = (x++) + (++y);first of all the right hand side expression will be evaluated.Here you can see that

yhas pre increment operator, so value ofywill increase 1 and will be added into the current value ofx. Result of the expression will be stored intozand then post increment operator will increase the value of x by 1.So it is similar to the sequence of instructions given in 3 lines.

Actually there is no option like none of these or compiler dependent that is why we can go for the concepts of sequence point logic .