MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Which of the following correctly initializes an array to contain four elements each with value 0?I. int[ ] arr = { 0, 0, 0, 0};II. int[ ] arr = new int[4];III. int[ ] arr = new int[4]; for(int i = 0; i < arr.length; i++) arr[i] = 0;
A
I only
B
I and II only
C
I, II, and III
D
I and III
Explanation: 

Detailed explanation-1: -Which of the following correctly declares an array? a)int array[10]; b)int array; c)array10; d)array array[10]; Correct answer is option ‘A’.

Detailed explanation-2: -Which of the following choices is the correct syntax for declaring/initializing an array of ten integers? int[] a = new int[10];

Detailed explanation-3: -To create an array, define the data type (like int ) and specify the name of the array followed by square brackets []. To insert values to it, use a comma-separated list, inside curly braces: int myNumbers[] = 25, 50, 75, 100; We have now created a variable that holds an array of four integers.

Detailed explanation-4: -2. What is the index number of the last element of an array with 9 elements? Explanation: Because the first element always starts at 0. So it is on 8 position.

There is 1 question to complete.