Challenge - 5 Problems
Assignment Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
β Predict Output
intermediate1:30remaining
Output of compound assignment with addition
What is the output of this C code snippet?
C
int main() { int a = 5; a += 3; printf("%d", a); return 0; }
Attempts:
2 left
π‘ Hint
The += operator adds the right value to the left variable.
β Incorrect
The operator 'a += 3' adds 3 to the current value of a (which is 5), so a becomes 8.
β Predict Output
intermediate1:30remaining
Result of bitwise AND assignment
What will be printed by this C program?
C
int main() { int x = 12; // binary 1100 x &= 5; // binary 0101 printf("%d", x); return 0; }
Attempts:
2 left
π‘ Hint
Bitwise AND compares each bit of two numbers and returns 1 only if both bits are 1.
β Incorrect
12 (1100) & 5 (0101) = 0100 which is 4 in decimal.
β Predict Output
advanced2:00remaining
Output of chained assignment with multiplication
What is the output of this code?
C
int main() { int a = 2, b = 3, c = 4; a *= b *= c; printf("%d %d %d", a, b, c); return 0; }
Attempts:
2 left
π‘ Hint
Remember that assignment operators return the assigned value and evaluate right to left.
β Incorrect
First, b *= c means b = 3 * 4 = 12. Then a *= b means a = 2 * 12 = 24. c remains 4.
β Predict Output
advanced1:30remaining
Effect of division assignment on float variable
What will this program print?
C
int main() { float f = 10.0f; f /= 4; printf("%.2f", f); return 0; }
Attempts:
2 left
π‘ Hint
Division assignment divides the variable by the right value and stores the result.
β Incorrect
10.0 divided by 4 is 2.5, printed with two decimals as 2.50.
β Predict Output
expert2:00remaining
Final value after multiple compound assignments
What is the final value of variable x after running this code?
C
int main() { int x = 1; x += 2; x *= 3; x -= 4; x /= 2; printf("%d", x); return 0; }
Attempts:
2 left
π‘ Hint
Apply each assignment operator step by step in order.
β Incorrect
x starts at 1, then x += 2 β 3, x *= 3 β 9, x -= 4 β 5, x /= 2 β 2 (integer division).