Open In App

C Quiz – 111 | Question 3

Like Article
Like
Save
Share
Report

Pick the best statement for the below:




int arr[50] = {0,1,2,[47]=47,48,49};


(A) This isn’t allowed in C and it’ll give compile error
(B) This is allowed in C as per standard. Basically, it’ll initialize arr[0], arr[1], arr[2], arr[47], arr[48] and arr[49] to 0,1,2,47,48 and 49 respectively. The remaining elements of the array would be initialized to 0.


Answer: (B)

Explanation: In C, initialization of array can be done for selected elements as well. By default, the initializer start from 0th element. Specific elements in array can be specified by []. It should be noted that the remaining elements (i.e. the ones not mentioned in array initialization) would be initialized to 0. For example, “int arr[10] = {100, [5]=100,[9]=100}” is also legal in C. This initializes arr[0], arr[5] and arr[9] to 100. All the remaining elements would be 0.

Quiz of this Question


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads