The correct syntax for multiplying and assigning is 'x *= 5;'. It combines multiplication and assignment.
Step 2: Check other options for syntax errors
x =* 5; 'x =* 5;' is invalid syntax. x = *5; 'x = *5;' is invalid because '*5' is not a valid expression. x = x *5; 'x = x *5;' is correct but not a compound assignment operator.
Final Answer:
x *= 5; -> Option D
Quick Check:
'*=' is multiply and assign operator [OK]
Hint: Use '*=' to multiply and assign in one step [OK]
Common Mistakes:
Writing '=*' instead of '*='
Forgetting space or semicolon
Using 'x = *5;' which is invalid
3. What is the output of the following code?
int a = 10; a += 5; a -= 3; printf("%d", a);
medium
A. 8
B. 15
C. 12
D. 10
Solution
Step 1: Calculate after first operation 'a += 5;'
Starting with a = 10, adding 5 gives a = 15.
Step 2: Calculate after second operation 'a -= 3;'
Subtracting 3 from 15 gives a = 12.
Final Answer:
12 -> Option C
Quick Check:
10 + 5 - 3 = 12 [OK]
Hint: Apply each operator step-by-step to track value [OK]
Common Mistakes:
Adding and subtracting in wrong order
Confusing '+=' and '-=' effects
Ignoring initial value of variable
4. Identify the error in the following code snippet:
int x = 7; x +== 3; printf("%d", x);
medium
A. Syntax error due to '+==' operator
B. Runtime error due to invalid operation
C. No error, output is 10
D. Logical error, output is wrong
Solution
Step 1: Check the operator '+==' in the code
The operator '+==' does not exist in C. The correct operator for addition assignment is '+='.
Step 2: Understand the effect of invalid operator
Using '+==' causes a syntax error and the code will not compile.
Final Answer:
Syntax error due to '+==' operator -> Option A
Quick Check:
Invalid operator '+==' causes syntax error [OK]
Hint: Use '+=' not '+==' for addition assignment [OK]
Common Mistakes:
Typing '+==' instead of '+='
Assuming '+==' works like '=='
Ignoring compiler error messages
5. Given the code below, what is the final value of result?
int result = 20; result /= 4; result *= 3; result %= 5; result += 2; printf("%d", result);