Challenge - 5 Problems
Default Value Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of default values for int and bool?
Consider the following C# code snippet. What will be printed when it runs?
C Sharp (C#)
int defaultInt = default; bool defaultBool = default; Console.WriteLine($"{defaultInt}, {defaultBool}");
Attempts:
2 left
💡 Hint
Default value of int is zero and default value of bool is false.
✗ Incorrect
In C#, default for int is 0 and for bool is false. So the output is 0, False.
❓ Predict Output
intermediate2:00remaining
What is the default value of a reference type?
What will this C# code print?
C Sharp (C#)
string defaultString = default; Console.WriteLine(defaultString == null ? "null" : defaultString);
Attempts:
2 left
💡 Hint
Default value of reference types is null.
✗ Incorrect
Reference types like string have null as their default value in C#.
❓ Predict Output
advanced2:00remaining
Default value of a struct with fields
Given this struct and code, what is the output?
C Sharp (C#)
struct Point { public int X; public int Y; }
Point p = default;
Console.WriteLine($"X={p.X}, Y={p.Y}");Attempts:
2 left
💡 Hint
Struct fields get default values too.
✗ Incorrect
Struct fields are value types and get default values. So both X and Y are 0.
❓ Predict Output
advanced2:00remaining
Default value of nullable types
What will this code print?
C Sharp (C#)
int? nullableInt = default;
Console.WriteLine(nullableInt.HasValue);Attempts:
2 left
💡 Hint
Nullable types default to null, so HasValue is false.
✗ Incorrect
Nullable types default to null, so HasValue is false.
🧠 Conceptual
expert2:00remaining
Why does default(T) behave differently for value and reference types?
Which statement best explains the behavior of
default(T) in C#?Attempts:
2 left
💡 Hint
Think about how value and reference types store data differently.
✗ Incorrect
Value types have a zero-equivalent default (like 0 for int), while reference types default to null because they store references to objects.