Which of the below statements correctly initializes an array ?Select one or more:a.double mark[5]={5.5,8.5,9.5};b.double mark[5]={5.5,8.5,9.5,3.5,2.5};c.double mark[ ]=new double[ ]{5.5,8.5,9.5,3.5,2.5};d.double mark[ ]={5.5,8.5,9.5,3.5,2.5};
Question
Which of the below statements correctly initializes an array ?Select one or more:a.double mark[5]={5.5,8.5,9.5};b.double mark[5]={5.5,8.5,9.5,3.5,2.5};c.double mark[ ]=new double[ ]{5.5,8.5,9.5,3.5,2.5};d.double mark[ ]={5.5,8.5,9.5,3.5,2.5};
Solution
The correct statements for initializing an array are:
b. double mark[5]={5.5,8.5,9.5,3.5,2.5}; d. double mark[ ]={5.5,8.5,9.5,3.5,2.5};
Explanation:
Option b is correct because it declares an array of size 5 and initializes it with 5 values.
Option d is also correct because it declares an array and initializes it with 4 values. The size of the array is determined by the number of values provided in the initialization.
Option a is incorrect because it declares an array of size 5 but only initializes it with 3 values.
Option c is incorrect because the syntax used (new keyword) is not valid in C or C++. It is used in Java to initialize an array.
Similar Questions
Which of the following is not a correct way to initialize an array?a.int n[ 5 ] = { 0, 7, 0, 3, 8, 2 };b.int n[] = { 0, 7, 0, 3, 8, 2 };c.int n[ 5 ] = { 7 };d.int n[ 5 ] = { 9, 1, 9 };
Which of the following is the correct way to declare and initialize an array in Java?a. int[ ] numbers = new int[5] {1, 2, 3, 4, 5}; b. int[ ] numbers = {1, 2, 3, 4, 5};c. int numbers[ ] = new int[ ]{1, 2, 3, 4, 5};d. int numbers = [1, 2, 3, 4, 5];Question 3Answera.Option a and Option bb.Option b and Option cc.Option cd.Option b
Which of the following is not a valid method to initialize an array in C/C++?*1 pointA. int values[5] = {1, 2, 3};B. int values[] = {1, 2, 3, 4, 5}C. int values[5];D. int[] values = {1, 2, 3, 4, 5};
Which of these is an incorrect Statement?a) It is necessary to use new operator to initialize an arrayb) Array can be initialized using comma separated expressions surrounded by curly bracesc) Array can be initialized when they are declaredd) None of the mentioned
Which of these is an incorrect Statement?ans.None of the mentionedArray can be initialized when they are declared.Array can be initialized using comma separated expressions surrounded by curly braces. It is necessary to use new operator to initialize an array. Previous Marked for Review Next
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.