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 1–5 of 54

Q1GATE 2026 (Session 2)2 marksNAT
Consider the following ANSI-C program.
#include <stdio.h>
 int main(){
  int *ptr, a, b, c;
  a=5; b=11; c=20;
  ptr=&a; *ptr=c; ptr=&c;
  a=*(&b); c=*ptr-a;
  printf("%d",c);
  return(0);
 } 
The output of this program is ________ . (answer in integer)
Note: Assume that the program compiles and runs successfully.

Q2GATE 2025 (Session 1)1 markNAT
The pseudocode of a function fun() is given below:

fun(int A[0,...,n-1])
{
    for i=0 to n-2
	for j=0 to n-i-2
	    if (A[j] > A[j+1])
		then swap A[j] and A[j+1]
}
Let A[0,…,29]A[0, \dots, 29] be an array storing 30 distinct integers in descending order. The number of swap operations that will be performed, if the function fun() is called with A[0,…,29]A[0, \dots, 29] as argument, is __________. (Answer in integer)

Q3GATE 2025 (Session 1)1 markNAT

#include <stdio.h>
void foo(int *p, int x) {
    *p = x;
}

int main() {
    int *z;
    int a = 20, b = 25;
    z = &a;
    foo(z, b);
    printf("%d", a);
    return 0;
}
The output of the given C program is __________. (Answer in integer)

Q4GATE 2025 (Session 2)1 markMCQ−0.33 if wrong
Consider the following C program:

#include <stdio.h>

void stringcopy(char *, char *);

int main(){
    char a[30] = "@#Hello World!";
    stringcopy(a, a + 2);
    printf("%s\n", a);
    return 0;
}

void stringcopy(char *s, char *t) {
    while(*t)
        *s++ = *t++;
}
Which ONE of the following will be the output of the program?

Q5GATE 2025 (Session 2)2 marksNAT
Consider the following C program:

#include <stdio.h>

int main(){
    int a;
    int arr[5] = {30,50,10};
    int *ptr;
    ptr = &arr[0] + 1;
    a = *ptr;
    (*ptr)++;
    ptr++;
    printf("%d", a + (*ptr) + arr[1]);
    return 0;
}
The output of the above program is ___________. (Answer in integer)

Keep practising

Topics in Programming in C

All CS topics ›