Challenge - 5 Problems
Array Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of array length after declaration
What is the output of this C# code snippet?
C Sharp (C#)
int[] numbers = new int[5]; Console.WriteLine(numbers.Length);
Attempts:
2 left
💡 Hint
Remember that the Length property returns the number of elements in the array.
✗ Incorrect
The array 'numbers' is declared with size 5, so its Length property returns 5.
❓ Predict Output
intermediate2:00remaining
Value of array element after declaration
What is the output of this C# code snippet?
C Sharp (C#)
int[] values = new int[3]; Console.WriteLine(values[1]);
Attempts:
2 left
💡 Hint
Default values for int elements in a new array are important here.
✗ Incorrect
In C#, int arrays are initialized with default value 0 for each element.
❓ Predict Output
advanced2:00remaining
Output of array initialization with values
What is the output of this C# code snippet?
C Sharp (C#)
string[] fruits = new string[] {"apple", "banana", "cherry"}; Console.WriteLine(fruits[2]);
Attempts:
2 left
💡 Hint
Array indexing starts at zero.
✗ Incorrect
The element at index 2 is "cherry" in the initialized array.
❓ Predict Output
advanced2:00remaining
Error type when accessing invalid index
What error does this C# code produce when run?
C Sharp (C#)
int[] arr = new int[2]; Console.WriteLine(arr[3]);
Attempts:
2 left
💡 Hint
Accessing an index outside the array bounds causes a runtime error.
✗ Incorrect
Accessing index 3 in an array of size 2 throws IndexOutOfRangeException.
🧠 Conceptual
expert2:00remaining
Number of elements in a declared array
How many elements does the array contain after this declaration in C#?
double[] data = new double[10];
Attempts:
2 left
💡 Hint
The number inside the brackets specifies the array size.
✗ Incorrect
The array 'data' is declared with size 10, so it contains 10 elements indexed 0 to 9.