0
0
C Sharp (C#)programming~20 mins

Assignment and compound assignment in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Assignment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
AHi there
BHi
Cthere
DHi+ there
Attempts:
2 left
💡 Hint
The += operator adds the right string to the left string.
Predict Output
intermediate
2: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);
A10
B15
C25
D30
Attempts:
2 left
💡 Hint
Remember operator precedence: multiplication and addition.
Predict Output
advanced
2: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);
A2
B2.25
C2.5
DSyntax error
Attempts:
2 left
💡 Hint
Division between double and int results in double.
Predict Output
advanced
2: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);
ACompilation error
BTrue
CFalse
DRuntime error
Attempts:
2 left
💡 Hint
Can you add booleans with += in C#?
🧠 Conceptual
expert
3: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);
ACompilation error
B5
Cnull
D15
Attempts:
2 left
💡 Hint
The ??= operator assigns only if the variable is null.