GATE CSE Programming in C PYQs
In GATE CS, Programming in C is tested extensively through rigorous code tracing, pointer mechanics, and fundamental semantics rather than high-level syntax tri… Read the guide
- Questions
- 74
- Asked
- since 2011
- Total marks
- 111
- Marks / paper
- 4.3
74 GATE CSE Programming in C PYQs with solutions, from Programming and Data Structures. Browse all GATE CSE PYQs.
Questions
Every official paper that asked this topic, newest first.
- GATE CSE 2026 Set 1 · Q34Consider the following program in C:
#include <stdio.h> void func(int i, int j) { if(i < j) { int i = 0; while (i < 10) { j += 2; i++; } } printf("%d", i); } int main() { int i = 9, j = 10; func(i, j); return 0; }The output of…NAT1 markEasySolve - GATE CSE 2026 Set 1 · Q39Consider the following code snippet in C language that computes the number of nodes in a non-empty singly linked list pointed to by the pointer variable
head.struct node{ int elt; struct node *next; }; int getListSize (struct node *head) { if( E1 ) return 1; return E2; }…MCQ2 marksEasySolve - GATE CSE 2026 Set 2 · Q17In C runtime environment, which one of the following is stored in heap?MCQ1 markEasySolve
- GATE CSE 2026 Set 2 · Q19Consider the following three ANSI-C programs, P1, P2, and P3. Which one of the following statements is true?MCQ1 markEasyDiagramSolve
- GATE CSE 2026 Set 2 · Q60Consider 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…NAT2 marksEasySolve - GATE CSE 2025 Set 1 · Q34
#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)NAT1 markEasySolve - GATE CSE 2025 Set 1 · Q62Let
LISTbe a datatype for an implementation of linked list defined as follows:typedef struct list { int data; struct list *next; } LIST;Suppose a program has created two linked lists, L1 and L2, whose contents are given in the figure below (code for creating L1 and L2 is not…NAT2 marksMediumDiagramSolve - GATE CSE 2025 Set 1 · Q63Consider the following C program:
#include <stdio.h> int gate (int n) { int d, t, newnum, turn; newnum = turn = 0; t=1; while (n>=t) t *= 10; t /=10; while (t>0) { d = n/t; n = n%t; t /= 10; if (turn) newnum = 10*newnum + d; turn = (turn + 1) % 2; } return newnum; } int main () { printf ("%d", gate(14362)); return 0; }…NAT2 marksMediumSolve - GATE CSE 2025 Set 2 · Q19Consider the following C program:
#include <stdio.h> void stringcopy(char *, char *); int main() { char a[30] = "@#Hello World!"; stringcopy(a, a + 2); printf("%s ", a); return 0; } void stringcopy(char *s, char *t) { while(*t) *s++ = *t++; }Which ONE of the following…MCQ1 markMediumSolve - GATE CSE 2025 Set 2 · Q33
int x=126, y=105;do {if(x>y) x=x-y;else y=y-x;} while(x!=y);printf("%d",x);The output of the given C code segment is ________ . (Answer in integer)NAT1 markEasySolve - GATE CSE 2025 Set 2 · Q62Consider 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)NAT2 marksEasySolve - GATE CSE 2025 Set 2 · Q63Consider the following C program:
#include <stdio.h> int g(int n) { return (n+10); } int f(int n) { return g(n*2); } int main() { int sum, n; sum=0; for (n=1; n<3; n++) sum += g(f(n)); printf ("%d", sum); return 0; }The output of the given C program is ________.…NAT2 marksEasySolve - GATE CSE 2024 Set 1 · Q18Consider the following C program:
#include <stdio.h> int main() { int a = 6; int b = 0; while(a < 10) { a = a / 12 + 1; a += b; } printf("%d", a); return 0; }Which one of the following statements is CORRECT?MCQ1 markEasySolve - GATE CSE 2024 Set 1 · Q33Consider the operator precedence and associativity rules for the arithmetic operators given in the table below. The value of the expression as per the above rules is ________NAT1 markMediumDiagramSolve
- GATE CSE 2024 Set 1 · Q48Consider the following C function definition.
int f(int x, int y) { for (int i=0; i<y; i++) { x=x+x+y; } return x; }Which of the following statements is/are TRUE about the above function?MSQ2 marksMediumSolve - GATE CSE 2024 Set 2 · Q13Consider the following C program. Assume parameters to a function are evaluated from right to left.
#include <stdio.h> int g(int p) { printf("%d", p); return p; } int h(int q) { printf("%d", q); return q; } void f(int x, int y) { g(x); h(y); } int main() { f(g(10),h(20)); }Which one of…MCQ1 markEasySolve - GATE CSE 2024 Set 2 · Q33Consider 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?MSQ1 markMediumSolve - GATE CSE 2024 Set 2 · Q36What 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; }MCQ2 marksMediumSolve - GATE CSE 2024 Set 2 · Q42Consider an array that contains positive integers. A subarray of 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 that contains at most two distinct integers. The code has…MCQ2 marksMediumSolve
- GATE CSE 2023 · Q35The integer value printed by the ANSI-C program given below is ________.
#include<stdio.h> int funcp(){ static int x = 1; x++; return x; } int main(){ int x,y; x = funcp(); y = funcp()+x; printf("%d ", (x+y)); return 0; }NAT1 markEasySolve - GATE CSE 2022 · Q21What 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 ", x, z[0], z[1]); return 0; }MCQ1 markEasySolve - GATE CSE 2022 · Q43What 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(" "); } return 0; }MCQ2 marksMediumSolve - GATE CSE 2022 · Q44What is printed by the following ANSI C program?
#include<stdio.h> int main(int argc, char *argv[]){ char a = 'P'; char b = 'x'; char c = (a & b) + '*'; char d = (a | b) - '-'; char e = (a ^ b) + '+'; printf("%c %c %c ", c, d, e); return 0; }ASCII encoding for…MCQ2 marksMediumDiagramSolve - GATE CSE 2021 Set 1 · Q37Consider the following ANSI C program.
#include <stdio.h> int main() { int i, j, count; count = 0; i = 0; for (j = -3; j <= 3; j++) { if ((j >= 0) && (i++)) count = count + j; } count = count + i; printf("%d", count); return 0; }Which one of the…MCQ2 marksMediumSolve - GATE CSE 2021 Set 1 · Q48Consider the following ANSI C function:
int SimpleFunction(int Y[], int n, int x) { int total = Y[0], loopIndex; for (loopIndex = 1; loopIndex <= n - 1; loopIndex++) total = x * total + Y[loopIndex]; return total; }Let be an array of 10 elements with , for all …NAT2 marksEasySolve - GATE CSE 2021 Set 2 · Q10Consider the following ANSI C program.
#include <stdio.h> int main(){ int arr[4][5]; int i, j; for (i=0; i<4; i++){ for (j=0; j<5; j++){ arr[i][j] = 10*i + j; } } printf("%d", *(arr[1] + 9)); return 0; }What is the output of the above program?MCQ1 markMediumSolve - GATE CSE 2021 Set 2 · Q23Consider the following ANSI C function:
int SomeFunction(int x, int y) { if ((x == 1) || (y == 1)) return 1; if (x == y) return x; if (x > y) return SomeFunction(x - y, y); if (y > x) return SomeFunction(x, y - x); }The value returned bySomeFunction(15, 255)is ________.NAT1 markEasySolve - GATE CSE 2021 Set 2 · Q35Consider the following ANSI C program:
#include <stdio.h> #include <stdlib.h> struct Node{ int value; struct Node *next;}; int main(){ struct Node *boxE, *head, *boxN; int index = 0; boxE = head = (struct Node *) malloc(sizeof(struct Node)); head->value = index; for (index = 1; index <= 3; index++){ boxN = (struct Node *) malloc(sizeof(struct Node)); boxE->next = boxN; boxN->value = index; boxE = boxN; } for (index = 0; index <= 3; index++) { printf("Value at index %d is %d ", index, head->value); head = head->next; printf("Value at index %d is %d ", index+1, head->value); } }…MCQ2 marksMediumSolve - GATE CSE 2020 · Q22Consider 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 ", *(*(a+**a+2)+3)); return(0); }The output of the program is…NAT1 markMediumSolve - GATE CSE 2020 · Q46Consider the following C functions.
int fun1(int n) { static int i = 0; if (n > 0) { ++i; fun1(n-1); } return(i); } int fun2(int n) { static int i = 0; if (n > 0) { i = i + fun1(n); fun2(n-1); } return(i); }The return value offun2(5)…NAT2 marksMediumSolve - GATE CSE 2020 · Q48Consider the following C functions.
int tob(int b, int* arr){ int i; for(i=0; b>0; i++){ if(b%2) arr[i]=1; else arr[i]=0; b = b/2; } return(i); } int pp(int a,int b) { int arr[20]; int i, tot = 1, ex, len; ex = a; len = tob(b,arr); for(i=0; i<len; i++){ if(arr[i]==1) tot = tot * ex; ex = ex * ex; } return(tot); }…NAT2 marksMediumSolve - GATE CSE 2019 · Q18Consider the following C program:
#include <stdio.h> int jumble(int x, int y){ x=2*x+y; return x; } int main(){ int x=2, y=5; y=jumble(y,x); x=jumble(y,x); printf("%d ", x); return 0; }The value printed by the program is _______.NAT1 markEasySolve - GATE CSE 2019 · Q24Consider 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 ", ip[1]); return 0; }The number that will be displayed on execution of the program is _______.NAT1 markEasySolve - GATE CSE 2019 · Q27Consider the following C program:
#include <stdio.h> int r(){ static int num=7; return num--; } int main(){ for (r();r();r()) printf("%d",r()); return 0; }Which one of the following values will be displayed on execution of the programs?MCQ2 marksMediumSolve - GATE CSE 2018 · Q2Consider the following C program.
#include<stdio.h> struct Ournode{ char x,y,z; }; int main() { struct Ournode p = {'1', '0', 'a'+2}; struct Ournode *q = &p; printf ("%c, %c", *((char*)q+1), *((char*)q+2)); return 0; }The output of this program is:MCQ1 markEasySolve - GATE CSE 2018 · Q21Consider the following C program:
#include <stdio.h> int counter = 0; int calc (int a, int b) { int c; counter++; if (b==3) return (a*a*a); else { c = calc(a, b/3); return (c*c*c); } } int main () { calc(4, 81); printf ("%d", counter); }The output of this…NAT1 markEasySolve - GATE CSE 2017 Set 1 · Q8Consider the C code fragment given below.
typedef struct node { int data; node* next; } node; void join(node* m, node* n){ node* p = n; while(p->next != NULL) { p = p->next; } p->next = m; }Assuming that \(m\) and \(n\) point to valid NULL-terminated linked lists, invocation ofjoin…MCQ1 markEasySolve - GATE CSE 2017 Set 1 · Q13Consider the following C code:
#include <stdio.h> int *assignval(int *x, int val) { *x = val; return x; } void main () { int *x = malloc(sizeof(int)); if(NULL == x) return; x = assignval(x, 0); if(x) { x = (int *)malloc(sizeof(int)); if(NULL == x) return; x = assignval(x, 10); } printf("%d ", *x); free(x); }…MCQ1 markMediumSolve - GATE CSE 2017 Set 1 · Q53Consider the following C program.
#include <stdio.h> #include <string.h> void printlength(char *s, char *t) { unsigned int c = 0; int len = ((strlen(s) - strlen(t)) > c) ? strlen(s): strlen(t); printf("%d ", len); } void main() { char *x = "abc"; char *y = "defgh"; printlength(x,y); }…NAT2 marksEasySolve - GATE CSE 2017 Set 1 · Q55The output of executing the following C program is _________ .
#include <stdio.h> int total(int v) { static int count = 0; while(v) { count += v&1; v >>= 1; } return count; } void main() { static int x = 0; int i = 5; for(; i > 0; i--) { x = x + total(i); } printf("%d ", x); }NAT2 marksMediumSolve - GATE CSE 2017 Set 2 · Q2Match the following:MCQ1 markEasyDiagramSolve
- GATE CSE 2017 Set 2 · Q14Consider the following function implemented in C:
void printxy(int x, int y) { int *ptr; x = 0; ptr = &x; y = *ptr; *ptr = 1; printf("%d,%d",x,y); }The output of invokingprintxy(1,1)isMCQ1 markEasySolve - GATE CSE 2017 Set 2 · Q37Consider the C program fragment below which is meant to divide
xbyyusing repeated subtractions. The variablesx,y,qandrare allunsigned int.while (r >= y) { r = r - y; q = q + 1; }Which of the…MCQ2 marksMediumSolve - GATE CSE 2017 Set 2 · Q43Consider the following snippet of a C program. Assume that
swap (&x, &y)exchanges the contents ofxandy.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]); }…NAT2 marksMediumSolve - GATE CSE 2017 Set 2 · Q54Consider the following C Program.
#include<stdio.h> int main() { int m = 10; int n, n1; n = ++m; n1 = m++; n--; --n1; n -= n1; printf("%d", n); return 0; }The output of the program is _________.NAT2 marksEasySolve - GATE CSE 2017 Set 2 · Q55Consider 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 _________.NAT2 marksMediumSolve - GATE CSE 2016 Set 1 · Q12Consider the following C program.
void f(int, short); void main() { int i = 100; short s = 12; short *p = &s; __________ ; // call to f() }Which one of the following expressions, when placed in the blank above, will NOT result in a type checking error?MCQ1 markEasySolve - GATE CSE 2016 Set 1 · Q15Consider 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 ", a); }…NAT1 markEasySolve - GATE CSE 2016 Set 1 · Q34The following function computes the maximum value contained in an integer array
p[]of size ().int max(int *p, int n) { int a=0, b=n-1; while (__________) { if (p[a] <= p[b]) { a = a+1; } else { b = b-1; } } return p[a]; }The…MCQ2 marksMediumSolve - GATE CSE 2016 Set 2 · Q12The 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); }NAT1 markEasySolve - GATE CSE 2016 Set 2 · Q35The following function computes for positive integers X and Y.
int exp(int X, int Y) { int res = 1, a = X, b = Y; while ( b != 0 ){ if ( b%2 == 0) { a = a*a; b = b/2; } else { res = res*a; b = b-1; } } return res; }Which one of the following conditions…MCQ2 marksMediumSolve - GATE CSE 2016 Set 2 · Q37Consider the following program:
int f(int *p, int n) { if (n <= 1) return 0; else return max(f(p+1,n-1),p[0]-p[1]); } int main() { int a[] = {3,5,2,6,4}; printf("%d", f(a,5)); }Note: returns the maximum of and . The value printed by this program is _______.NAT2 marksMediumSolve - GATE CSE 2015 Set 1 · Q11The 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); }NAT1 markEasySolve - GATE CSE 2015 Set 1 · Q33Consider the following pseudo code, where and are positive integers.
begin q := 0 r := x while r >= y do begin r := r - y q := q + 1 end endThe post condition that needs to be satisfied after the program terminates isMCQ2 marksEasySolve - GATE CSE 2015 Set 1 · Q35What is the output of the following C code? Assume that the address of is 2000 (in decimal) and an integer requires four bytes of memory.
int main () { unsigned int x[4][3] = {{1,2,3},{4,5,6},{7,8,9},{10,11,12}}; printf("%u, %u, %u", x+3, *(x+3), *(x+2)+3); }MCQ2 marksMediumSolve - GATE CSE 2015 Set 1 · Q42Consider the following C program segment.
while(first <= last) { if (array[middle] < search) first = middle + 1; else if (array[middle] == search) found = TRUE; else last = middle - 1; middle = (first + last)/2; } if (first > last) notPresent = TRUE;The cyclomatic…NAT2 marksEasySolve - GATE CSE 2015 Set 3 · Q7Consider the following C program segment.
#include <stdio.h> int main() { char s1[7] = "1234", *p; p = s1 + 2; *p = '\0'; printf("%s", s1); }What will be printed by the program?MCQ1 markEasySolve - GATE CSE 2015 Set 3 · Q26Consider the following C program.
<code>#include<stdio.h>
int main( ) { static int a[ ] = {10, 20, 30, 40, 50}; static int *p[ ] = {a, a+3, a+4, a+1, a+2}; intptr = p; ptr++; printf("%d%d", ptr-p,ptr);}</code> The output of the program is ____________.NAT1 markMediumSolve - GATE CSE 2015 Set 3 · Q48Consider the following C program:
#include<stdio.h> int main( ) { int i, j, k = 0; j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5; k -= --j; for(i = 0; i < 5; i++) { switch(i + k) { case 1: case 2: printf(" %d", i+k); case 3: printf(" %d", i+k); default: printf(" %d", i+k); } } return 0; }…NAT2 marksMediumSolve - GATE CSE 2015 Set 3 · Q54Consider the following C program.
#include<stdio.h> int f1(void); int f2(void); int f3(void); int x = 10; int main( ) { int x = 1; x += f1( ) + f2( ) + f3( ) + f2( ); printf("%d", x); return 0; } int f1() { int x = 25; x++; return x;} int f2() { static int x = 50; x++; return x;} int f3() { x *= 10; return x;}…NAT2 marksMediumSolve - GATE CSE 2014 Set 1 · Q10Consider the following program in C language:
#include <stdio.h> main() { int i; int *pi = &i; scanf("%d",pi); printf("%d ", i+5); }Which one of the following statements is TRUE?MCQ1 markEasySolve - GATE CSE 2014 Set 1 · Q41Consider the following C function in which
sizeis the number of elements in the arrayE:int MyX(int *E, unsigned int size) { int Y = 0; int Z; int i, j, k; for(i = 0; i < size; i++) Y = Y + E[i]; for(i = 0; i < size; i++) for(j = i; j < size; j++) { Z = 0; for(k = i; k <= j; k++) Z = Z + E[k]; if (Z > Y) Y = Z; } return Y; }…MCQ2 marksMediumSolve - GATE CSE 2014 Set 2 · Q10Consider the function
funcshown below:int func(int num) { int count = 0; while (num) { count++; num>>= 1; } return (count); }The value returned byfunc(435)is ________.NAT1 markEasySolve - GATE CSE 2014 Set 2 · Q11Suppose
nandpareunsigned intvariables in a C program. We wish to setpto . Ifnis large, which one of the following statements is most likely to setpcorrectly?MCQ1 markMediumSolve - GATE CSE 2014 Set 3 · Q10Let A be a square matrix of size . Consider the following pseudocode. What is the expected output?
C = 100; for i = 1 to n do for j = 1 to n do { Temp = A[i][j] + C; A[i][j]= A[j][i]; A[j][i] = Temp - C; } for i = 1 to n do for j = 1 to n do output (A[i][j]);MCQ1 markEasySolve - GATE CSE 2014 Set 3 · Q11The minimum number of arithmetic operations required to evaluate the polynomial for a given value of , using only one temporary variable is _______.NAT1 markMediumSolve
- GATE CSE 2014 Set 3 · Q42Consider the C function given below. Assume that the array
listAcontainsn() elements, sorted in ascending order.int ProcessArray(int *listA, int x, int n) { int i, j, k; i = 0; j = n-1; do { k = (i+j)/2; if (x <= listA[k]) j = k-1; if (listA[k] <= x) i = k+1; }while (i <= j); if (listA[k] == x) return(k); else return -1; }…MCQ2 marksMediumSolve - GATE CSE 2013 · Q50Common Data for Questions 50 and 51:
The procedure given below is required to find and replace certain characters inside an input character string supplied in array
A. The characters to be replaced are supplied in arrayoldc, while their respective replacement characters are supplied in…MCQ2 marksMediumSolve - GATE CSE 2013 · Q51Common Data for Questions 50 and 51:
The procedure given below is required to find and replace certain characters inside an input character string supplied in array
A. The characters to be replaced are supplied in arrayoldc, while their respective replacement characters are supplied in…MCQ2 marksEasySolve - GATE CSE 2012 · Q3What will be the output of the following C program segment?
char inChar = 'A' ; switch ( inChar ) { case 'A' : printf ("Choice A\ n") ; case 'B' : case 'C' : printf ("Choice B") ; case 'D' : case 'E' : default : printf ( " No Choice" ) ; }MCQ1 markEasySolve - GATE CSE 2012 · Q48Common Data for Questions 48 and 49:
Consider the following C code segment.
int a, b, c = 0; void prtFun(void); main( ) { static int a = 1; /* Line 1 */ prtFun( ); a += 1; prtFun( ); printf(" %d %d ", a, b); } void prtFun(void) { static int a = 2; /* Line 2 */ int b = 1; a += ++b; printf(" %d %d ", a, b); }…MCQ2 marksMediumSolve - GATE CSE 2012 · Q49Common Data for Questions 48 and 49:
Consider the following C code segment.
int a, b, c = 0; void prtFun(void); main( ) { static int a = 1; /* Line 1 */ prtFun( ); a += 1; prtFun( ); printf(" %d %d ", a, b); } void prtFun(void) { static int a = 2; /* Line 2 */ int b = 1; a += ++b; printf(" %d %d ", a, b); }…MCQ2 marksMediumSolve - GATE CSE 2011 · Q5A company needs to develop a strategy for software product development for which it has a choice of two programming languages L1 and L2. The number of lines of code (LOC) developed using L2 is estimated to be twice the LOC developed with L1. The product will have to be maintained for five years. Various parameters for…MCQ1 markMediumDiagramSolve
- GATE CSE 2011 · Q22What does the following fragment of C program print?
Char c[] = "GATE2011"; char *p = c; printf("%s", p + p[3] - p[1]);MCQ1 markMediumSolve
What GATE tests in Programming in C
Concepts, patterns, formulas and traps distilled from past papers.
In GATE CS, Programming in C is tested extensively through rigorous code tracing, pointer mechanics, and fundamental semantics rather than high-level syntax trivia. Questions emphasize pointer arithmetic and multidimensional array decay, storage classes (especially static local variables), evaluation order, side effects of increment/decrement operators, parameter passing mechanisms (pass-by-value vs pass-by-reference), and recursive program state tracking. The topic features a nearly balanced split between NAT and MCQ items across 1-mark and 2-mark categories, demanding precise, bug-free execution traces without a compiler.
Core concepts
- Pointer arithmetic and scale factors based on base type
- Multidimensional array decaying into pointers (pointer to array vs array of pointers)
- Storage classes (auto, register, static, extern) and lifetime vs scope
- Pre-increment vs post-increment evaluation and sequence point rules
- Short-circuit evaluation of logical AND (&&) and logical OR (||)
- Pass-by-value vs pass-by-reference/pointer mechanics
- Recursive call stack tracking with local vs static state retention
- Dynamic memory management (malloc, free, memory leaks, dangling pointers)
- String literals, ASCII arithmetic, character pointers, and null termination ('\0')
- Bitwise operators (&, |, , >) and binary number manipulation
- Switch-case fall-through behavior without break statements
- Recursive function execution and call stack reduction
- Base conditions and termination checks
- Implementation of Euclidean algorithm via repeated subtraction in C
- Return value propagation across nested call frames
Recurring question patterns
Pointer Arithmetic and Multidimensional Array Indexing
Commonmixed2 marks2026, 2025, 2024, 2022Evaluating complex pointer expressions involving 1D/2D/3D arrays, array decaying, pointer subtraction, array subscript commutativity (), and double dereferencing ().
Storage Classes, Variable Scope, and Shadowing
CommonNAT2 marks2026, 2023, 2020, 2019Tracing code containing static local variables retaining state across multiple recursive or iterative function calls, global vs local variable shadowing, and lifetime vs scope distinctions.
Parameter Passing and Pointer Swapping Idioms
Commonmixed1 marks2026, 2025, 2024, 2019Testing the distinction between pass-by-value and pass-by-reference using pointers, including classic traps where pointer formal parameters are reassigned locally without dereferencing.
Short-Circuit Evaluation, Precedence, and Side Effects
Commonmixed1 marks2024, 2022, 2021, 2017Evaluating expressions involving logical operators (&&, ||) where side-effects like pre/post increment (++i, i++) or assignment are skipped due to short-circuiting, or custom operator precedence tables.
Loop Invariants, Algorithm Semantics, and Verification
OccasionalMCQ2 marks2025, 2024, 2017, 2016Formulating correct pre/post-conditions, identifying loop invariants (e.g., division by repeated subtraction, binary exponentiation), or filling missing loop termination/update guards.
String Manipulation and Null Termination Pitfalls
Occasionalmixed1 marks2025, 2024, 2017, 2015Tracing pointer-based string copies or scans that miss copying the null terminator '\0', unsigned size_t differences producing underflow, or ASCII arithmetic offsets.
Dynamic Memory Allocation and Memory Layout
OccasionalMCQ1 marks2026, 2021, 2017Identifying memory leaks, dangling pointers, uninitialized heap memory accesses, or matching C declarations with memory segments (Stack, Heap, Data/BSS).
Mathematical Algorithm Trace / Output Evaluation
CommonNAT1 marks2021A C recursive function implementing a fundamental mathematical operation (e.g., Euclidean GCD via repeated subtraction) is given with multiple base conditions and recursive steps. Candidates must trace the execution or identify the closed-form computation to determine the return value for given arguments.
Formulas GATE uses
Pointer Subtraction
Used when computing the numerical result of subtracting two pointers pointing to elements of the same array.
2D Array Element Address Calculation
Used for mapping multi-dimensional array indices to flat memory offsets in row-major layout.
Array Subscript Equivalence
Used to resolve commutative and unorthodox array indexing expressions in C snippets.
Cyclomatic Complexity
Used to calculate McCabe's cyclomatic complexity where is the count of predicate/decision conditions in the control flow.
Integer Division Loop Invariant
Used to verify formal loop invariants in repeated subtraction integer division routines.
Euclidean Subtraction GCD
Used when analyzing recursive functions that reduce two numbers by repeated subtraction until equality or 1 is reached.
Examiner traps in Programming in C
- Assuming pointer subtraction returns byte difference rather than the number of typed elements.
- Forgetting switch-case fall-through when break statements are omitted.
- Evaluating the right operand of && or || when the left operand already determines the result (short-circuit skipping side-effects like i++).
- Confusing (*p)++ (incrementing the dereferenced value) with *p++ (dereferencing current address then advancing pointer).
- Forgetting that static local variables in recursive functions retain cumulative updates across all activation records.
- Overlooking missing null terminators ('\0') in manual string copying loops, causing trailing characters to persist in memory.
- Failing to account for unsigned arithmetic wrap-around when subtracting unsigned types like sizet from strlen().
- Thinking a function that takes pointer parameters swaps them in main when the function swaps pointer values locally instead of dereferenced targets.
- Simulating all subtraction steps manually one-by-one rather than recognizing the modulo/GCD invariant, leading to arithmetic mistakes or time loss.
- Overlooking premature termination base cases (e.g., `x == 1 || y == 1`).
- Off-by-one or parameter swapping errors during the recursive calls.
How questions are asked
- Exact output tracing of C code snippets (NAT/MCQ)
- Return value determination of recursive functions with static variables (NAT)
- Identification of missing loop invariant, condition, or expression (MCQ/MSQ)
- Pointer arithmetic and multidimensional array evaluation (NAT/MCQ)
- Short-circuit operator and side-effect expression evaluation (MCQ/NAT)
- Memory allocation behavior analysis (memory leak, segmentation fault, dangling pointer) (MCQ)
- Cyclomatic complexity computation of C control structures (NAT)
- Evaluate return value of a recursive C function for specific input arguments
Paper trends
Shift towards Numerical Answer Type (NAT) questions requiring exact printed output calculations rather than multiple-choice guessing.
2026, 2025, 2023, 2021, 2020, 2019, 2018, 2017, 2015
Introduction of non-standard operator precedence tables where candidates must compute expression values based on customized grammar rules rather than default C precedence.
2024
Inclusion of Multi-Select Questions (MSQ) examining algorithmic invariants, asymptotic function bounds, and string pointer validity across multiple scenarios.
2024
Increased focus on subtle C standard specifications such as unsigned arithmetic wrap-around with strlen(), uninitialized struct next pointer dereferencing, and block-scope variable shadowing.
2026, 2025, 2024, 2021, 2017
Focus on concise ANSI C code implementing arithmetic algorithms via recursion, testing understanding of control flow and reduction to base cases within NAT format.
2021
Difficulty notes
Easy questions typically test direct syntax rules, single function calls with pass-by-value/pass-by-pointer, basic switch fall-through, or standard 1D pointer dereferencing. Medium questions combine multiple concepts: nested loops with complex pointer arithmetic on 2D/3D arrays, static variables in mutual/deep recursion, short-circuit boolean expressions with post-increment side effects, or unsigned arithmetic traps. Hard/complex questions require formulating algebraic invariants for loops, identifying obscure memory leak conditions, or tracing customized operator precedence grammars.