A student executes the following code to increase the value of a variable 'x' by 2.
He has written the following statement, which is incorrect.
x = +2;
What will be the correct statement?
A. x +=2;
B. x=2;
C. x=x+2;
Let's carefully analyze the problem:
The student wrote:
x = +2;
This does not increase x by 2; it just assigns the value +2 to x.
To increase x by 2, the correct statements are:
x += 2; → This is shorthand for x = x + 2;. ✅
x = x + 2; → Explicitly increases x by 2. ✅
x = 2; → This assigns 2 to x, it does not increase it. ❌
So the correct options are A and C.
Answer: (d) Both A and C