MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
How can we initialize an array in C language?
A
int arr[2]=(10, 20);
B
int arr(2)={10, 20} ;
C
int arr[2] = {10, 20};
D
int arr(2) = (10, 20) ;
Explanation: 

Detailed explanation-1: -Array Initialization Using a Loop The following syntax uses a “for loop” to initialize the array elements. This is the most common way to initialize an array in C. // declare an array. int my array[5];

Detailed explanation-2: -The initializer for an array is a comma-separated list of constant expressions enclosed in braces ( ). The initializer is preceded by an equal sign ( = ). You do not need to initialize all elements in an array.

Detailed explanation-3: -By using an array initializer, we can initialize the array elements. See the below code, for example. int arr[6] = 10, 20, 30, 40, 50, 60; The above line indicates initializing an array of size 6 with elements in the same order.

There is 1 question to complete.