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 6–10 of 54

Q6GATE 2024 (Session 2)1 markMSQ
Consider the following C function definition.

int fX(char *a){ 
char *b = a; 
while(*b)
b++;
return b - a;}
Which of the following statements is/are TRUE?

One or more options are correct.

Q7GATE 2024 (Session 2)2 marksMCQ−0.67 if wrong
What is the output of the following C program?

#include <stdio.h>
int main() {
double a[2]={20.0, 25.0}, *p, *q;
p = a;
q = p + 1;
printf("%d,%d", (int)(q - p), (int)(*q - *p));
return 0;}

Q8GATE 2024 (Session 2)2 marksMCQ−0.67 if wrong
Consider an array X that contains n positive integers. A subarray of X is defined to be a sequence of array locations with consecutive indices.
The C code snippet given below has been written to compute the length of the longest subarray of X that contains at most two distinct integers. The code has two missing expressions labelled (P) and (Q).

int first=0, second=0, len1=0, len2=0, maxlen=0;
for (int i=0; i < n; i++) {
	 if (X[i] == first) {
		len2++; len1++;
	 } else if (X[i] == second) {
		len2++;
		len1 = (P) ;
		second = first;
	 } else {
		len2 = (Q) ;
		len1 = 1; second = first;
	 }
	 if (len2 > maxlen) {
		maxlen = len2;
	}
	  first = X[i];
}
Which one of the following options gives the CORRECT missing expressions?

(Hint: At the end of the i-th iteration, the value of len1 is the length of the longest subarray ending with X[i] that contains all equal values, and len2 is the length of the longest subarray ending with X[i] that contains at most two distinct values.)

Q9GATE 20221 markMCQ−0.33 if wrong
What is printed by the following ANSI C program?

#include <stdio.h>
int main(int argc, char *argv[])
{
int x = 1, z[2] = {10, 11};
int *p=NULL; p=&x;
*p=10;
p =&z[1];
*(&z[0]+1)+=3;
printf("%d, %d, %d \n",x,z[0],z[1]); return   0;
}

Q10GATE 20222 marksMCQ−0.67 if wrong
What is printed by the following ANSI C program?
#include <stdio.h>
int main(int argc, char *argv[])
{
 int a[3][3][3] =
 {{1, 2, 3, 4, 5, 6, 7, 8, 9},
 {10, 11, 12, 13, 14, 15, 16, 17, 18},
 {19, 20, 21, 22, 23, 24, 25, 26, 27}};
int i = 0, j = 0, k = 0; 
for( i = 0; i < 3; i++ ){

     for(k = 0; k < 3; k++ ) 
      printf("%d ", a[i][j][k]);
 printf(" \n");
}
return 0;
}

Keep practising

Topics in Programming in C

All CS topics ›