Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Test  >  Programming and Data Structures  >  Test: Arrays - 2 - Computer Science Engineering (CSE) MCQ

Arrays - 2 - Free MCQ Practice Test with solutions, GATE CSE (CSE) Programming


MCQ Practice Test & Solutions: Test: Arrays - 2 (15 Questions)

You can prepare effectively for Computer Science Engineering (CSE) Programming and Data Structures with this dedicated MCQ Practice Test (available with solutions) on the important topic of "Test: Arrays - 2". These 15 questions have been designed by the experts with the latest curriculum of Computer Science Engineering (CSE) 2026, to help you master the concept.

Test Highlights:

  • - Format: Multiple Choice Questions (MCQ)
  • - Duration: 45 minutes
  • - Number of Questions: 15

Sign up on EduRev for free to attempt this test and track your preparation progress.

Test: Arrays - 2 - Question 1

Elements in an array are accessed _____________

Detailed Solution: Question 1

Elements in an array are accessed randomly. In Linked lists, elements are accessed sequentially.

*Answer can only contain numeric values
Test: Arrays - 2 - Question 2

What is the output for the given program?
int sum(int arr[], int n)
{
int sum = 0; 
for (int i = 0; i < n; i++)
sum += arr[i];
return sum;
}
 main()
{
int arr[] = {12, 30, 40, 15};
int n = sizeof(arr) / sizeof(arr[0]);
cout << sum(arr, n);
return 0;
}


Detailed Solution: Question 2

The program is described as:

In the given code, Consider the address of the array as 100.
The main function has an array arrr[] = {12, 30, 40, 15};
int n = sizeof(arr) / sizeof(arr[0]);
sizeof(arr) = 16(4 x 2) i.e four elements and each size is 2. 
sizeof(arr[0]) = Size of element arr[0] i.e first element size = 2.
So n becomes n=16/2
∴ n=4
And sum(arr, n)
Here arr is the address of the array. 
sum(100, 5)

The sum function calculates the summation of elements
Initially, the sum=0 sums each element and stores it in the sum variable.
sum=12+30+40+15
sum=97 and returns the sum variable to the main function i.e 97.
Hence the correct answer is 97.

Test: Arrays - 2 - Question 3

Assuming int is of 4bytes, what is the size of int arr[15];?

Detailed Solution: Question 3

Since there are 15 int elements and each int is of 4bytes, we get 15*4 = 60bytes.

Test: Arrays - 2 - Question 4

Find the output of the following program

int main()
{
  int i; int arr[6]={1}; 

  for(i=0;i<6;i++)
  {
     printf("%d",arr[i]);
  }
return 0;
}

Detailed Solution: Question 4

  • Array of size 6 is declared and is initialized by 1.
  • arr[0] will contain 1 and rest are by default initialized as zero.
  • for loop will print all that values starting from arr[0] to arr[5].

arr[0]=1
arr[1]=0
arr[2]=0
arr[3]=0
arr[4]=0
arr[5]=0

Final output print by the program is 1 0 0 0 0 0.

Test: Arrays - 2 - Question 5

When does the ArrayIndexOutOfBoundsException occur?

Detailed Solution: Question 5

ArrayIndexOutOfBoundsException is a run-time exception and the compilation is error-free.

Test: Arrays - 2 - Question 6

A two-dimensional array named Arr is with the range Arr[10........20, 25......45]. The base address of the array is 10 and the size of each element is 2 bytes. What will be the location of Arr[15][30] using column major order?

Detailed Solution: Question 6

Column major order concept: 

  • Column major order means the element in a column is stored adjacent to each other. This basically works in a 2d and 3d array.
  • Now we are given the base address along with the size of each element and the construction of a 2d array(row and column number )
  • First, we have to calculate the no. of rows here = (Row upper limit - Row lower limit) + 1 = (20 - 10) + 1 = 11.
  • We need no. of the column if the ques will ask about Row major order.
  • There is a formula available to calculate it directly(Rather than going into deep how the formula came, it's better to remember the formula.)

Formula:-
Address of A[I][J] is can be calculated with the formula is A[I][J] = B + ((J – LC) * M + (I – LR))*W.
where;

  • I- Row subset of an element whose address is to be found ( 15 here)
  • J = Column Subset of an element whose address is to be found,(30 here)
  • B- Base address(10 here)
  • W- storage size of one element  (2 bytes here)
  • LR- the lower limit of row (u can take start index of the matrix)- (10 in this ques)
  • LC-Lower limit of column(start column index of the matrix) - (25 in this ques)
  • M- number of rows given in the matrix. (11 here)

 
Now solve the equation by solving the inner bracket first.
10+[5*11+5] *2  = 10+(60)*2 = 10+120= 130 will be the answer.

Test: Arrays - 2 - Question 7

If integer requires two bytes space, then what will be the size of the following 'C’ array?

int array[3][4]=(0);

Detailed Solution: Question 7

An array is defined as the collection of similar types of data items stored at contiguous memory locations. 
int array[3][4] = (0);
Here Array is an integer array. which is in a two-dimensional array of 3 rows and 4 columns. So each row has 4 elements and there are three rows.
Hence total number of elements = 3 x 4 =12
Each element of size = 2 bytes.
So size of array is = 12 x 2 bytes =24 bytes.
Hence the correct answer is 24 bytes.

Test: Arrays - 2 - Question 8

What is the output of the following Java code?

public class array
{
    public static void main(String args[])
    {
        int []arr = {1,2,3,4,5};
        System.out.println(arr[2]);
        System.out.println(arr[4]);
    }
}

Detailed Solution: Question 8

Array indexing starts from 0.

Test: Arrays - 2 - Question 9

Consider the following ANSI C program.

#include

int main()

{
   int arr[4][5];
   int i, j;
  for(i =0; i<4; i++)
  {
    for (j =0; j<5; j++)
    {
       arr [i][j] = 10 * i + j;
    }
  }
     print("%d", *(arr[1] + 9));
     return 0;
}

Q. What is the output of the above program?

Detailed Solution: Question 9

*(arr[1] + 9) can be written as arr[1][9].
as C doesn't follow bound check and follow the row major ordering
arr[1][5] = arr[2][0]  // arr[1][4] will be first row of array and then arr[2][0] will be second row of array 
arr[1][6] = arr[2][1]
arr[1][7] = arr[2][2]
arr[1][8] = arr[2][3]
arr[1][9] = arr[2][4]
arr[2][4] = 10*i + j = 10*2+4 = 24

Option 4 is the answer.

Test: Arrays - 2 - Question 10

The correct syntax for initialization of a one-dimensional array is _________.

Detailed Solution: Question 10

  • In the following declaration, the array name is num.
  • The size of the array is four.
  • The array is initialized with four elements 1,2,3,4.

Test: Arrays - 2 - Question 11

How do you instantiate an array in Java?

Detailed Solution: Question 11

Note that int arr[]; is declaration whereas int arr[] = new int[3]; is to instantiate an array.

Test: Arrays - 2 - Question 12

Which of these best describes an array?

Detailed Solution: Question 12

Array contains elements only of the same type.

Test: Arrays - 2 - Question 13

Consider the following C program segment.

#include
int main()
{
char s1[7] = "1234", *p;
p = s1 + 2; *p = ‘0’;
printf("%s", s1);
}

Q. What will be printed by the program?

Detailed Solution: Question 13

Where \0 is a null character 
After *p = '0';   \\s1[2] = '0'
100  101 102 103  104


printf(“%s”, s1) will print all starting from address location 100 until the null character.
Output: 1204 

Test: Arrays - 2 - Question 14

An array name is a

Detailed Solution: Question 14

An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together.

When an array is used as a value and array name represents the address of the first element. When an array is not used as a value its name represents the whole array.

Array name is a type of name or a type of any element name that is share by all elements of an array but its indexes are different. Array name handle as a constant pointer, it can never change during execution of a program. Array name is also used to reach its all element.

Therefore Option 3 is correct

Test: Arrays - 2 - Question 15

Consider the following program of ‘C’

main ( )
{
static int a [ ] = { 1, 2, 3, 4, 5, 6, 7, 8 } ;
int i;
for(i = 2; I < 6; ++i)
a [a [i] ] = a [i];
for (I = 0; I < 8 ; ++i)
printf (“%d”, a[i]);
}

Q. The output of the program is :

Detailed Solution: Question 15

Array a

for(I = 2; I < 6; ++i)            // initially i = 2 and 2< 6(true)
a [a [i] ] = a [i];         
Iteration 1:
i = 2;
a[a[2]] = a[2]
a[3] = [3]

Iteration 2:
When i = 3, 3 < 6 (true)
a[a[3]] = a[3]
a[3] = 3              // as in iteration 1, a[3] becomes was 3

Iteration 3:
When i = 4
a[a[4]] = a[4]
a[5] = 5

Iteration 4:
When i = 5, 5 < 6 (true)
a[a[5]] = a[5]
a[5] = 5                // as in iteration 3 a[5] becomes 5.

In next iteration i becomes and condition 6 < 6 false here.
Content of array A are as follows:

Finally, it prints: 1 2 3 3 5 5 7 8

161 docs|30 tests
Information about Test: Arrays - 2 Page
In this test you can find the Exam questions for Test: Arrays - 2 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Arrays - 2, EduRev gives you an ample number of Online tests for practice
Download as PDF