Practice mode C#

What is printed by: int arr = new int; Console.WriteLine(arr);?

Correct answer B. 0

Explanation

When an array is created with new, every element is set to its type's default value. For int that is 0, so arr[1] prints 0. A string array would contain null elements and a bool array false. Accessing arr[3] would throw IndexOutOfRangeException, because valid indexes for a length-3 array are 0 to 2.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.