X -= Y + 1 means

2011

X -= Y + 1 means

Answer: D. X = X - Y - 1ConceptIn C, every compound assignment operator is defined by a single rule: a statement of the form E1 op= E2 is equivalent to E1 = E1 op (E2). The whole…

  1. A.

    X = X - Y + 1

  2. B.

    X = -X - Y - 1

  3. C.

    X = -X + Y + 1

  4. D.

    X = X - Y - 1

Attempted by 205 students.

Show answer & explanation

Correct answer: D

Concept

In C, every compound assignment operator is defined by a single rule: a statement of the form E1 op= E2 is equivalent to E1 = E1 op (E2). The whole right-hand side E2 is treated as one operand, exactly as if it were written inside parentheses, and E1 is evaluated only once. The parentheses are part of the definition, not an optional extra.

Applying the rule here

  1. Identify the three parts of the statement: E1 is X, the operator op is subtraction, and E2 is the complete expression Y + 1.

  2. Expand by the rule, keeping E2 parenthesised as the definition requires: X = X - (Y + 1).

  3. Distribute the minus sign over both terms inside the parentheses to remove them: X = X - Y - 1.

Cross-check with numbers

Take X = 10 and Y = 3. Then Y + 1 = 4, so after the statement X must hold 10 - 4 = 6. Evaluating every offered form with the same two values:

Form

Value when X = 10 and Y = 3

X = X - Y + 1

8

X = -X - Y - 1

-14

X = -X + Y + 1

-6

X = X - Y - 1

6

Only X = X - Y - 1 reproduces 6, so the statement is equivalent to X = X - Y - 1.

Where the parentheses matter

The usual slip is to drop the parentheses and subtract Y alone, then add 1 separately. That changes X by 1 - Y instead of by -(Y + 1). The two differ by exactly 2 for every value of Y, so dropping the parentheses is never harmless.

Explore the full course: Tpsc Assistant Technical Officer

Loading lesson…