Challenge - 5 Problems
Assignment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of compound assignment with strings
What is the output of this C# code snippet?
C Sharp (C#)
string s = "Hi"; s += " there"; Console.WriteLine(s);
Attempts:
2 left
💡 Hint
The += operator adds the right string to the left string.
✗ Incorrect
The += operator appends the string on the right to the string on the left, so s becomes "Hi there".
❓ Predict Output
intermediate2:00remaining
Value after compound assignment with integers
What is the value of x after running this code?
C Sharp (C#)
int x = 5; x *= 3 + 2; Console.WriteLine(x);
Attempts:
2 left
💡 Hint
Remember operator precedence: multiplication and addition.
✗ Incorrect
The expression x *= 3 + 2 is evaluated as x *= (3 + 2), so x = 5 * 5 = 25.
❓ Predict Output
advanced2:00remaining
Output of compound assignment with mixed types
What is the output of this code?
C Sharp (C#)
double d = 4.5; int i = 2; d /= i; Console.WriteLine(d);
Attempts:
2 left
💡 Hint
Division between double and int results in double.
✗ Incorrect
d /= i divides d by i, so 4.5 / 2 = 2.25.
❓ Predict Output
advanced2:00remaining
Effect of compound assignment on boolean variables
What error or output does this code produce?
C Sharp (C#)
bool flag = true; flag += false; Console.WriteLine(flag);
Attempts:
2 left
💡 Hint
Can you add booleans with += in C#?
✗ Incorrect
The += operator is not defined for bool types, so this causes a compilation error.
🧠 Conceptual
expert3:00remaining
Understanding compound assignment with nullable types
Given the code below, what is the value of n after execution?
C Sharp (C#)
int? n = null; n ??= 10; n += 5; Console.WriteLine(n);
Attempts:
2 left
💡 Hint
The ??= operator assigns only if the variable is null.
✗ Incorrect
n starts as null, so n ??= 10 sets n to 10. Then n += 5 adds 5, so n becomes 15.