Challenge - 5 Problems
Variable Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of variable initialization with implicit typing
What is the output of this C# code snippet?
C Sharp (C#)
var number = 10; var text = "Hello"; var result = number + text.Length; Console.WriteLine(result);
Attempts:
2 left
💡 Hint
Remember that var infers the type and text.Length returns an integer.
✗ Incorrect
The variable 'number' is 10, 'text.Length' is 5, so adding them results in 15.
❓ Predict Output
intermediate2:00remaining
Value of uninitialized variable
What happens when you try to use an uninitialized local variable in C#?
C Sharp (C#)
int x; // Console.WriteLine(x); // Uncommenting this line causes what?
Attempts:
2 left
💡 Hint
Local variables must be assigned before use in C#.
✗ Incorrect
Local variables in C# must be initialized before use, otherwise compilation fails.
❓ Predict Output
advanced2:00remaining
Output of variable shadowing in nested scopes
What is the output of this C# code?
C Sharp (C#)
int value = 5; { int value = 10; Console.WriteLine(value); } Console.WriteLine(value);
Attempts:
2 left
💡 Hint
Check if C# allows redeclaring a variable with the same name in an inner block.
✗ Incorrect
C# does not allow redeclaring a variable with the same name in an inner scope if the outer variable is still in scope, so this causes a compilation error.
❓ Predict Output
advanced2:00remaining
Output of nullable variable initialization and usage
What is the output of this C# code?
C Sharp (C#)
int? number = null; number ??= 100; Console.WriteLine(number);
Attempts:
2 left
💡 Hint
The ??= operator assigns the value only if the variable is null.
✗ Incorrect
Since 'number' is null, the ??= operator assigns 100 to it, so output is 100.
🧠 Conceptual
expert2:00remaining
Behavior of const and readonly variables
Which statement about const and readonly variables in C# is correct?
Attempts:
2 left
💡 Hint
Think about when the values are fixed and where assignments are allowed.
✗ Incorrect
const variables are fixed at compile time and assigned only once at declaration; readonly variables can be assigned once at declaration or in constructor, allowing runtime initialization.