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 21–25 of 54

Q21GATE 2017 (Session 2)2 marksNAT
Consider the following snippet of a C program. Assume that swap (&x, &y) exchanges the contents of x and y.

int main ( ) {
int array[]={3,5,1,4,6,2};
int done =0 ;
int i ;
while (done == 0) {
   done = 1;
   for (i = 0; i <=4; i ++) {
   if (array [i] < array [i +1]) {
       swap (& array [i], &array [i+1]);
       done = 0;
    }
}
for (i = 5 ; i >=1; i --) {
if (array [i] > array [ i-1]) {
    swap ( & array [i] , &array [i-1]);
     done = 0;
  }
} }
printf ( " %d " , array [3] );
}
The output of the program is ____________.

Q22GATE 2017 (Session 2)2 marksNAT
Consider the following C Program.
 #include <stdio.h>
#include <string.h>
int main ( ) {
char* c = "GATECSIT2017";
char* p = c;
printf("%d", (int) strlen (c+2[p]-6[p]-1));
return 0;
}
The output of the program is _______________.

Q23GATE 2016 (Session 1)1 markNAT
Consider the following C program.

#include <stdio.h>
void mystery(int *ptra,int *ptrb){
   int *temp;
   temp =ptrb; 
   ptrb =ptra;
   ptra =temp;
}
int main(){
   int a=2016,b=0,c=4,d=42;
   mystery(&a, &b);
   if (a < c)
            mystery(&c, &a);
   mystery(&a, &d);
   printf("%d\n", a);
}
The output of the program is _________.

Q24GATE 2016 (Session 2)1 markNAT
The value printed by the following program is .

void f(int*p, int m){
     m =m+5;
     *p =*p+m;
      return;
}
void main(){
     int i=5, j=10;
     f(&i, j);
     printf("%d", i+j);
}

Q25GATE 2015 (Session 1)1 markNAT
The output of the following C program is__________.
  void f1(int a, int b) {
    int c;
    c=a; a=b; b=c;
}
void f2(int *a, int *b) {
    int c;
    c=*a; *a=*b; *b=c;
}
int main(){
    int a=4, b=5, c=6;
    f1(a,b);
    f2(&b, &c);
     printf("%d",c-a-b);
}

Keep practising

Topics in Programming in C

All CS topics ›