×

Arrays


1) Are the expressions arr and &arr same for an array of 10 integers?

  1. Yes
  2. No




2) How do you initialize an array in C?

  1. int arr[3] = (1,2,3);
  2. int arr(3) = {1,2,3}
  3. int arr[3] = {1,2,3};
  4. int arr(3) = (1,2,3);



3) Which of the following is a correct way to declare a multidimensional array in Java?

  1. int[][] arr;
  2. int arr[][];
  3. int []arr[];
  4. All of the mentioned



4) What does the following declaration mean? int (*ptr)[10];

  1. ptr is array of pointers to 10 integers
  2. ptr is a pointer to an array of 10 integers
  3. ptr is an array of 10 integers
  4. ptr is an pointer to array



5) For the following declaration of a function in C, pick the best statement int [] fun(void (*fptr)(int *));

  1. It will result in compile error.
  2. No compile error. fun is a function which takes a function pointer fptr as argument and return an array of int.
  3. No compile error. fun is a function which takes a function pointer fptr as argument and returns an array of int. Also, fptr is a function pointer which takes int pointer as argument and returns void
  4. No compile error. fun is a function which takes a function pointer fptr as argument and returns an array of int. The array of int depends on the body of fun i.e. what size array is returned. Also, fptr is a function pointer which takes int pointer as argument and returns void.



6) Does C perform array out of bound checking? What is the output of the following program?
int main()
{
    int i;
    int arr[5] = {0};
    for (i = 0; i <= 5; i++)
        printf("%d ", arr[i]);
    return 0;
}

  1. Compiler Error: Array index out of bound.
  2. The always prints 0 five times followed by garbage value
  3. The program always crashes.
  4. The program may print 0 five times followed by garbage value, or may crash if address (arr+5) is invalid.



7) What are the advantages of arrays?

  1. Easier to store elements of same data type
  2. Used to implement other data structures like stack and queue
  3. Convenient way to represent matrices as a 2D array
  4. All of the mentioned



8) What are the disadvantages of arrays?

  1. We must know before hand how many elements will be there in the array
  2. There are chances of wastage of memory space if elements inserted in an array are lesser than than the allocated size
  3. Insertion and deletion becomes tedious
  4. All of the mentioned



9) In an array of 2N elements that is both 2-ordered and 3-ordered, what is the maximum number of positions that an element can be from its position if the array were 1-ordered?

  1. 1
  2. 2
  3. N/2
  4. 2N - 1



10) Let A(1:8, -5:5, -10:5) be a three dimensional array. How many elements are there in the array A? A

  1. 1200
  2. 1408
  3. 33
  4. 1050