👉 Pointers & Arrays
Why it matters: The most frequent C topic in GATE. You must read *p++, a[i], *(a+i), p[1] and pointer differences without hesitation.
Subtopics
Each subtopic has its own page: idea, why, how, example, play, check. Mark each one understood when it clicks. 0 of 5 done.
1Pointers: address, dereference, aliasing
2Pointer arithmetic
3Arrays, decay and sizeof
4Two-dimensional arrays (row-major)
5Pointers to pointers
Formulas
Address of a[i]
base + i · sizeof(a[0])
Address of a[i][j] in int a[R][C]
base + (i·C + j) · sizeof(int)
Pointer difference
(p − q) = (address(p) − address(q)) / sizeof(*p)
Array and pointer equivalences
a[i] ≡ *(a + i) &a[i] ≡ a + i
sizeof
sizeof(int a[10]) = 40 bytes, but sizeof of an int* parameter = 8
2-D access
a[i][j] ≡ *(*(a + i) + j) ≡ *(a[i] + j)
What GATE asks from this
Question types seen repeatedly in past papers. More stars means more frequent.
★★★
Output of a pointer/array program
Draw the array, mark each pointer with an arrow, update on every statement (*p++, (*p)++, p[1]).
★★★
2-D / 3-D array indexing with a pointer expression
Convert to row-major offsets: *(*(a + i) + j).
★★★
Swap functions: value vs pointer vs pointer-to-pointer
Decide which copy is changed: only a **pointer to the pointer** changes the caller's pointer.
★★★
Page faults or cache misses from array traversal order
Row-major layout: walking down a column touches a new page or block each time.
Ratings are approximate, based on recurring patterns in past GATE CSE papers.
Previous year questions
11 real questions from the official GATE CSE papers (2014 to 2025), newest first, each with the official answer key and a worked solution. Questions are the property of the GATE organising institutes; this copy is for your personal study.
11 questions · 0 correct of 0 attempted · marks 0 / 17
Year:
GATE 2025 CS2 · Q62NAT2 marks
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 ______.GATE 2024 CS2 · Q36MCQ2 marks
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;
}GATE 2023 · Q57NAT2 marks
Consider the following two-dimensional array D in the C programming language, which is stored in row-major order:
int D[128][128];Demand paging is used for allocating memory and each physical page frame holds 512 elements of the array D. The Least Recently Used (LRU) page-replacement policy is used by the operating system. A total of 30 physical page frames are allocated to a process which executes the following code snippet:
for (int i = 0; i < 128; i++)
for (int j = 0; j < 128; j++)
D[j][i] *= 10;The number of page faults generated during the execution of this code snippet is ______.GATE 2022 · Q21MCQ1 mark
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;
}GATE 2022 · Q43MCQ2 marks
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;
}GATE 2020 · Q22NAT1 mark
Consider the following C program.
#include <stdio.h>
int main() {
int a[4][5] = {{1, 2, 3, 4, 5},
{6, 7, 8, 9, 10},
{11, 12, 13, 14, 15},
{16, 17, 18, 19, 20}};
printf("%d\n", *(*(a+**a+2)+3));
return(0);
}The output of the program is ______.GATE 2019 Set 2 · Q24NAT1 mark
Consider the following C program:
#include <stdio.h>
int main(){
int arr[]={1,2,3,4,5,6,7,8,9,0,1,2,5}, *ip=arr+4;
printf("%d\n", ip[1]);
return 0;
}The number that will be displayed on execution of the program is ______.GATE 2019 Set 2 · Q53NAT2 marks
Consider the following C program:
#include <stdio.h>
int main()
{
int a[] = {2, 4, 6, 8, 10};
int i, sum = 0, *b = a + 4;
for (i = 0; i < 5; i++)
sum = sum + (*b - i) - *(b - i);
printf ("%d\n", sum);
return 0;
}The output of the above C program is ______.GATE 2018 · Q29MCQ2 marks
Consider the following C program:
#include<stdio.h>
void fun1(char *s1, char *s2){
char *tmp;
tmp = s1;
s1 = s2;
s2 = tmp;
}
void fun2(char **s1, char **s2){
char *tmp;
tmp = *s1;
*s1 = *s2;
*s2 = tmp;
}
int main(){
char *str1 = "Hi", *str2 = "Bye";
fun1(str1, str2); printf("%s %s ", str1, str2);
fun2(&str1, &str2); printf("%s %s", str1, str2);
return 0;
}The output of the program above isGATE 2016 Set 1 · Q15NAT1 mark
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 ______.GATE 2014 Set 1 · Q10MCQ1 mark
Consider the following program in C language:
#include <stdio.h>
main()
{
int i;
int *pi = &i;
scanf("%d",pi);
printf("%d\n", i+5);
}Which one of the following statements is TRUE?Common traps
*p++ is *(p++), not (*p)++.p + 1 adds sizeof(*p) bytes.sizeof of an array parameter is the size of a pointer.
A 3-D initialiser with fewer braces is filled in row-major order, not row by row.