Challenge - 5 Problems
Array Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Array Initialization and Access
What is the output of the following C# code snippet?
DSA C#
int[] numbers = new int[4] {10, 20, 30, 40}; Console.WriteLine(numbers[2]);
Attempts:
2 left
💡 Hint
Remember that array indices start at 0 in C#.
✗ Incorrect
The array numbers has elements: 10 at index 0, 20 at index 1, 30 at index 2, and 40 at index 3. Accessing numbers[2] prints 30.
❓ Predict Output
intermediateOutput of Partially Initialized Array
What will be printed by this C# code?
DSA C#
int[] arr = new int[5]; arr[0] = 5; arr[4] = 10; Console.WriteLine(arr[2]);
Attempts:
2 left
💡 Hint
Uninitialized int array elements default to zero.
✗ Incorrect
In C#, integer arrays are initialized with zeros by default. Since arr[2] was not assigned, it prints 0.
❓ Predict Output
advancedOutput of Multidimensional Array Access
What is the output of this C# code snippet?
DSA C#
int[,] matrix = new int[2,3] { {1, 2, 3}, {4, 5, 6} }; Console.WriteLine(matrix[1, 2]);
Attempts:
2 left
💡 Hint
Remember the first index is the row, second is the column.
✗ Incorrect
The element at row 1, column 2 is 6 in the given 2x3 matrix.
❓ Predict Output
advancedOutput of Jagged Array Initialization and Access
What will this C# code print?
DSA C#
int[][] jagged = new int[2][]; jagged[0] = new int[] {1, 2}; jagged[1] = new int[] {3, 4, 5}; Console.WriteLine(jagged[1][2]);
Attempts:
2 left
💡 Hint
Jagged arrays are arrays of arrays with different lengths.
✗ Incorrect
The jagged array's second element is an array {3,4,5}. Accessing index 2 of that array prints 5.
🧠 Conceptual
expertArray Initialization Behavior in C#
Which statement about array initialization in C# is correct?
Attempts:
2 left
💡 Hint
Think about default values for reference and value types in C# arrays.
✗ Incorrect
In C#, arrays of reference types are initialized with null by default. Value types are initialized with their default values (e.g., 0 for int). Arrays cannot be resized after creation.
