Array and Pointer: GATE CS Previous Year Questions

Array and Pointer · Programming in C

54 questions · asked in 22 of 27 years (2000–2026)

MCQ 39 · MSQ 1 · NAT 141-mark 34 · 2-mark 20

2000Questions per year2026

Questions 46–50 of 54

Q46GATE 20041 markMCQ−0.33 if wrong
Consider the following C program which is supposed to compute the transpose of a given 4×44 \times 4 matrix M. Note that, there is an X in the program which indicates some missing statements. Choose the correct option to replace X in the program.
 #include <stdio.h>
#define ROW 4
#define COL 4
int M[ROW][COL] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
main()
{
    int i, j, t;
    for (i = 0; i < 4; ++i)
    {
        X
    }
    for (i = 0; i < 4; ++i)
        for (j = 0; j < 4; ++j)
            printf ("%d", M[i][j]);
}

Q47GATE 20041 markMCQ−0.33 if wrong
Consider the following C program segment:
char p[20];
char *s = "string";
int length = strlen(s);
int i;
for (i = 0; i < length; i++)
     p[i] = s[length - i];
printf("%s",p); 
The output of the program is

Q48GATE 20031 markMCQ−0.33 if wrong
In the following C program fragment, j, k, n and TwoLog_n are integer variables, and A is an array of integers. The variable n is initialized to an integer ≥\geq 3, and TwoLog_n is initialized to the value of 2∗⌈log2n⌉2*\left \lceil log_{2}n \right \rceil
 for (k = 3; k <= n; k++)
    A[k] = 0;
for (k = 2; k <= TwoLog_n; k++)
    for (j = k + 1; j <= n; j++)
        A[j] = A[j] || (j % k);
for (j = 3; j <= n; j++)
    if (!A[j]) printf("%d", j);
The set of number printed by this program fragment is

Q49GATE 20031 markMCQ−0.33 if wrong
Assume the following C variable declaration
int *A [10], B[10][10];
Of the following expressions
I A[2]
II A[2][3]
III B[1]
IV B[2][3]
which will not give compile-time errors if used as left hand sides of assignment statements in a C program?

Q50GATE 20011 markMCQ−0.33 if wrong
Consider the following three functions :
[P1]
  int * g (void) 
{ 
  int x= 10; 
  return (&x); 
}
[P2]
   int * g (void) 
{ 
  int * px; 
  *px= 10; 
  return px; 
} 
[P3]
  int *g (void) 
{ 
  int *px; 
  px = (int *) malloc (sizeof(int)); 
  *px= 10; 
  return px; 
} 
Which of the above three functions are likely to cause problems with pointers ?

Keep practising

Topics in Programming in C

All CS topics ›