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

2014

The following three 'C' language statements is equivalent to which single statement? y=y+1; z=x+y; x=x+1

  1. A.

    z = x + y + 2;

  2. B.

    z = (x++) + (++y);

  3. C.

    z = (x++) + (y++);

  4. D.

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

Attempted by 1012 students.

Show answer & explanation

Correct answer: B

The original code increments y first (y=y+1), then calculates z using the updated y and current x (z=x+y), and finally increments x (x=x+1). In the expression z = (x++) + (++y), ++y increments y before it is used in the addition, matching the first step. x++ uses the current value of x for the calculation but increments it afterwards, matching the third step. Thus, z receives the sum of original x and new y, consistent with the sequential statements.

Explore the full course: Isro