• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Arrays

Question 31

C program is given below: C
# include <stdio.h>
int main ()
{
        int i, j;
        char a [2] [3] = {{\'a\', \'b\', \'c\'}, {\'d\', \'e\', \'f\'}};
        char b [3] [2];
        char *p = *b;
        for (i = 0; i < 2; i++) {
              for (j = 0; j < 3; j++) {
              *(p + 2*j + i) = a [i] [j];
              }
        }
}
 /* Add code here. Remove these lines if not writing code */ 
What should be the contents of the array b at the end of the program?
  • a b
    c d
    e f
  • a d
    b e
    c f
  • a c
    e b
    d f
  • a e
    d c
    b f

Question 32

Consider the array A[]= {6,4,8,1,3} apply the insertion sort to sort the array . Consider the cost associated with each sort is 25 rupees , what is the total cost of the insertion sort when element 1 reaches the first position of the array  ?
  • 50
  • 25
  • 75
  • 100

Question 33

A one dimensional array A has indices 1....75. Each element is a string and takes up three memory words. The array is stored at location 1120 decimal. The starting address of A[49] is
 

  • 1267
     

  • 1164
     

  • 1264
     

  • 1169
     

Question 34

Which of the following is true about arrays in C?
 

  • For every type T, there can be an array of T.

  • For every type T except void and function type, there can be an array of T.

  • When an array is passed to a function, C compiler creates a copy of array.

  • 2D arrays are stored in column major form

Question 35

For the following declaration of a function in C, pick the best statement 
 

C
int [] fun(void (*fptr)(int *));
  • It will result in compile error.
     

  • No compile error. fun is a function which takes a function pointer fptr as argument and return an array of int.
     

  • 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.
     

  • 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.
     

Question 36

In C, 1D array of int can be defined as follows and both are correct. 
 

C
int array1D[4] = {1,2,3,4};
int array1D[] = {1,2,3,4};

But given the following definitions (along-with initialization) of 2D arrays 
 

C
int array2D[2][4] = {1,2,3,4,5,6,7,8}; /* (i) */
int array2D[][4] = {1,2,3,4,5,6,7,8}; /* (ii) */
int array2D[2][] = {1,2,3,4,5,6,7,8}; /* (iii) */
int array2D[][] = {1,2,3,4,5,6,7,8}; /* (iv) */

Pick the correct statements.
 

  • Only (i) is correct.
     

  • Only (i) and (ii) are correct.
     

  • Only (i), (ii) and (iii) are correct.
     

  • All (i), (ii), (iii) and (iv) are correct.
     

Question 37

The following function computes the maximum value contained in an integer array p[] of size n (n >= 1) 
 

C
int max(int *p, int n)
{
    int a=0, b=n-1;
    while (__________)
    {
        if (p[a] <= p[b])
        {
            a = a+1;
        }
        else
        {
            b = b-1;
        }
    }
    return p[a];
}

The missing loop condition is
 

  • a != n
     

  • b != 0
     

  • b > (a + 1)
     

  • b != a
     

There are 37 questions to complete.

Last Updated :
Take a part in the ongoing discussion