Skip to content
Early access — you're among the first to try PYQLabs. Share feedback
Concept drill

C programming

GATE CSE & IT · Programming - C Language · 2000-2026

103
PYQs
76%
keyed
3
elite explanations
25
years appeared

Study anchor

Source-book anchor pending for this concept.

Practice action

Start latest PYQ

PYQs in this concept

All concepts →
2026 PYQ

Consider the following C statements: char str1 = "Hello; / Statement S1 */ char str2 = "Hello;"; / Statement S2 */ int str3 = "Hello"; / Statement S3 */ Which of the following opti...

easyanswer keybasic explanation
2026 PYQ

Consider 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;...

easyanswer keyelite explanation
2026 PYQ

Consider the following program snippet. Assume that the program compiles and runs successfully. Further, assume that the fork( ) system call is always successful in creating a proc...

mediumbasic explanation
2026 PYQ

In C runtime environment, which one of the following is stored in heap?

easyanswer keybasic explanation
2026 PYQ

Consider 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...

easybasic explanation
2026 PYQ

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); }...

easybasic explanation
2025 Q19

Consider the following C program: #include void stringcopy (char *, char *); int main() { char a [30] = "@#Hello World!"; stringcopy (a, a + 2); printf("%s\n", a); return 0; } void...

mediumanswer key
2025 Q29

Suppose in a multiprogramming environment, the following C program segment is executed. A process goes into I/O queue whenever an I/O related operation is performed. Assume that th...

mediumanswer key
2025 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)

mediumanswer key
2025 Q34

#include 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 __________. (...

mediumanswer key
2025 Q61

#include int foo(int S[],int size) { if(size == 0) return 0; if(size == 1) return 1; if(S[0] != S[1]) return 1+foo(S+1,size-1); return foo(S+1,size-1); } int main() { int A[]={0,1,...

mediumanswer key
2025 Q62

Let LIST be 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...

mediumanswer key
2025 Q62

Consider the following C program: #include 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]); r...

mediumanswer key
2025 Q63

Consider the following C program: #include 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;...

mediumanswer key
2025 Q63

Consider the following C program: #include 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...

mediumanswer key
2025 PYQ

#include <stdio.h> int foo(int S[ ], int size) { if(size == 0) return 0; if(size == 1) return 1; if(S[0]!=S[1]) return 1 + foo(S + 1, size - 1); return foo(S + 1, size - 1); } int...

easybasic explanation
2025 PYQ

#include 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 _________....

easybasic explanation
2025 PYQ

Consider the following C program : #include 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 (...

mediumbasic explanation
2025 PYQ

Consider 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 The output of the...

easybasic explanation
2025 PYQ

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) + a...

easybasic explanation
2025 PYQ

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)

easybasic explanation
2024 Q13

Consider the following C program. Assume parameters to a function are evaluated from right to left. #include int g(int p) { printf("%d", p); return p; } int h(int q) { printf("%d",...

mediumanswer key
2024 Q18

Consider the following C program: #include 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 sta...

mediumanswer key
2024 Q19

Consider the following C program: #include void fX(); int main() { fX(); return 0;} void fX() { char a; if((a=getchar()) != '\n') fX(); if (a != '\n') putchar (a); } Assume that th...

mediumanswer key
2024 Q33

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?

mediumanswer key
2024 Q36

What is the output of the following C program? #include 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;}

mediumanswer key
2024 Q42

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 b...

mediumanswer key
2024 Q48

Consider 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 f...

mediumanswer key
2024 PYQ

Consider the following C program: #include <stdio.h> void fX(); int main() { fX(); return 0;} void fX() { char a; if ((a = getchar()) != '\n') fX(); if (a != '\n') putchar(a);} Ass...

easyanswer keybasic explanation
2024 PYQ

Consider 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 f...

mediumanswer keyelite explanation
2024 PYQ

Consider the following C program. Assume parameters to a function are evaluated from right to left. #include <studio.h> int g(int p) { printf("%d", p); return p; } int h(int q) { p...

easyanswer keybasic explanation
2024 PYQ

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?

easyanswer keybasic explanation
2024 PYQ

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 b...

mediumanswer keybasic explanation
2023 PYQ

Consider the following program: int main ( ) { f1( ); f2(2); f3( ); return (0); } int f1( ) { return (1); } int f2 (int X) { f3( ); if (X==1) return f1 ( ); else return (X*f2(X$$-$...

easyanswer keybasic explanation
2022 PYQ

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[...

easyanswer keybasic explanation
2022 PYQ

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,...

easyanswer keybasic explanation
2021 PYQ

Consider 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; } } print("%d", *(ar...

mediumanswer keybasic explanation
2021 PYQ

Consider 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 *...

easybasic explanation
2021 PYQ

Consider the following ANSI C function: int SomeFunction (int x, int y) { if ( (x == 1) I I (y == 1)) return 1; if (x == y) return x; if (x > y) return SomeFunction(x - y, y); if (...

easybasic explanation
2021 PYQ

Consider 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 =...

mediumanswer keybasic explanation
2020 PYQ

Consider 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...

easybasic explanation
2020 PYQ

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”...

mediumbasic explanation
2020 PYQ

Consider 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...

mediumbasic explanation
2019 PYQ

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 wil...

easybasic explanation
2019 PYQ

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...

easybasic explanation
2019 PYQ

Consider the following C function. void convert(int n){ if(n < 0) printf("%d",n); else { convert(n/2); printf("%d",n%2); } } Which one of the following will happen when the functio...

easyanswer keybasic explanation
2019 PYQ

Consider the following C program : #include<stdio.h> int r() { static int num=7; return num--; } int main() { for(r();r();r()) printf("%od ",r()); return 0; } Which one of the foll...

mediumanswer keybasic explanation
2019 PYQ

Consider the following C program : #include <stdio.h> int main(){ float sum = 0.0, j = 1.0, i = 2.0; while (i/j > 0.0625){ j = j + j; sum = sum + i/j; printf("%f\n", sum); } return...

easybasic explanation
2018 PYQ

Consider 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...

easy
2018 PYQ

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...

easyanswer key
2017 Q2

Match the following: (P) static char var; (Q) m = malloc(10); m = NULL; (R) char *ptr[10]; (S) register int var1; (i) Sequence of memory locations to store addresses (ii) A variabl...

mediumanswer key
2017 Q14

Consider 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 invoking printxy...

mediumanswer key
2017 Q37

Consider the C program fragment below which is meant to divide x by y using repeated subtractions. The variables x, y, q and r are all unsigned int. ```c while (r >= y) { r = r - y...

mediumanswer key
2017 Q38

Consider the following C function. ```c int fun(int n) { int i, j; for (i = 1; i <= n; i++) { for (j = 1; j < n; j += i) { printf("%d %d",i,j); } } } ``` Time complexity of fun in...

hardanswer key
2017 Q43

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...

mediumanswer key
2017 Q54

Consider the following C Program. #include int main() { int m = 10; int n, nl; n = ++m; n1 = m++; n--; --nl; n -= nl; printf("%d", n); return 0; } The output of the program is ____...

mediumanswer key
2017 Q55

Consider the following C Program. #include #include int main() { char* c = "GATECSIT2017"; char* p = c; printf("%d", (int)strlen(c+2[p]-6[p]-1)); return 0; } The output of the prog...

hardanswer key
2016 PYQ

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...

easy
2016 PYQ

Consider 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, w...

easyanswer key
2015 PYQ

Consider the following function written in the C programming language. void foo(char *a){ if ( *a && *a != ' '){ foo(a+1); putchar(*a); } } The output of the above function on inpu...

easyanswer key
2015 PYQ

What is the output of the following C code? Assume that the address of x is 2000 (in decimal) and an integer requires four bytes of memory. int main () { unsigned int x[4][3] = {{1...

mediumanswer key
2015 PYQ

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,...

easy
2015 PYQ

Consider 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?

easyanswer key
2015 PYQ

Consider the following C function. int fun ( int n ) { int x = 1, k ; if ( n == 1) return x ; for( k = 1 ; k < n ; ++ k ) x = x + fun( k ) * fun( n - k ) ; return x ; } The return...

medium
2015 PYQ

Consider the C program below. #include < stdio.h > int *A, stkTop; int stkFunc(int opcode, int val) { static int size=0, stkTop=0; switch (opcode) { case -1: size = val; break; cas...

medium
2014 PYQ

Consider the function func shown below: int func(int num) { int count = 0; while(num) { count++; num >>= 1; } return (count); } The value returned by func(435) is _________.

easy
2014 PYQ

Suppose n and p are unsigned int variables in a C program. We wish to set p to $${}^n{C_3}$$. If n is large, which one of the following statements is most likely to set p correctly...

mediumanswer key
2014 PYQ

Consider the following C functions in which size is the number of elements in the array E: int MyX(int *E, unsigned int size){ int Y = 0; int Z; int i,j,k; for(i = 0; i < size; i++...

mediumanswer key
2014 PYQ

Consider the C function given below. Assume that the array listA contains n (> 0) elements, sored in ascending order. int ProcessArray(int *listA, int x, int n) { int i, j, k; i =...

mediumanswer key
2014 PYQ

Consider the C function given below. int f(int j) { static int i = 50; int k; if (i == j) { printf("something"); k = f(i); return 0; } else return 0; } Which one of the following i...

easyanswer key
2014 PYQ

Consider the following function double f (double x) { if ( abs (x * x – 3) < 0. 01) return x; else return f (x / 2 + 1.5/x); } Give a value q (to 2 decimals) such that f(q) will re...

medium
2013 PYQ

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...

mediumanswer key
2013 PYQ

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...

mediumanswer key
2012 PYQ

What 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”) ; c...

easyanswer key
2012 PYQ

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("\n %d %d ", a, b); } void p...

mediumanswer key
2012 PYQ

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("\n %d %d ", a, b); } void p...

mediumanswer key
2011 PYQ

Consider the following recursive C function that takes two arguments: unsigned int foo (unsigned int n, unsigned int r) { if (n > 0) return((n % r) + foo(n/r, r)); else return 0; }...

easyanswer key
2011 PYQ

What does the following fragment of C-program print? char c[ ] = "GATE2011"; char *p = c; printf("%s", p + p[3] - p[1]);

mediumanswer key
2010 PYQ

The following C function takes a simply-linked list as input argument. It modifies the list by moving the last element to the front of the list and returns the modified list. Some...

easyanswer key
2010 PYQ

What does the following program print? #include < stdio.h > void f (int *p, int *q) { p = q; *p = 2; } int i = 0, j = 1; int main ( ){ f(&i, &j); printf ("%d %d \ n", i, j); return...

easyanswer key
2008 PYQ

The following C function takes a single-linked list of integers as a parameter and rearranges the elements of the list. The function is called with the list containing the integers...

easyanswer key
2008 PYQ

What is printed by the following C program? #include < stdio.h > int f(int x, int *py, int **ppz) { int y, z; **ppz += 1; z = **ppz; *py += 2; y = *py; x += 3; return x + y + z; }...

mediumanswer key
2008 PYQ

Choose the correct option to fill ? 1 and ? 2 so that the program below prints an input string in reverse order. Assume that the input string is terminated by a newline character....

easyanswer key
2008 PYQ

Consider the following C program that attempts to locate an element x in an array Y[] using binary search. The program is erroneous. 1. f(int Y[10], int x) { 2. int i, j, k; 3. i =...

mediumanswer key
2008 PYQ

Consider the following C program that attempts to locate an element x in an array Y[] using binary search. The program is erroneous. 1. f(int Y[10], int x) { 2. int i, j, k; 3. i =...

mediumanswer key
2007 PYQ

Consider the following C program segment where CellNode represents a node in a binary tree: struct CellNode { struct CellNOde *leftChild; int element; struct CellNode *rightChild;...

easyanswer key
2007 PYQ

Consider the following C program: #include #define EOF -1 void push (int); /* push the argument on the stack */ int pop (void); /* pop the top of the stack */ void flagError (); in...

mediumanswer key
2007 PYQ

Consider the following C function: int f(int n) { static int r = 0; if(n <= 0) return 1; if(n>3) { r = n; return f(n-2)+2; } return f(n-1)+r; } What is the value of f(5)?

mediumanswer key
2006 PYQ

The following function computes the value of m C n correctly for all legal values m and n (m≥1,n≥0 and m>n) int func(int m, int n) { if (E) return 1; else return(func(m -1, n) + fu...

easyanswer key
2005 PYQ

Consider the following C program: void foo (int n, int sum) { int k = 0, j = 0; if(n==0) return; k=n%10; j = n /10; sum = sum + k; foo(j, sum); printf("%d",k); } int main () { int...

easyanswer key
2005 PYQ

The following C function takes a single-linked list of integers as a parameter and rearranges the elements of the list. The function is called with the list containing the integers...

easyanswer key
2004 PYQ

Consider the following C program segment: char p[20]; char *s = "string"; int length = strlen(s); for(i=0; i < length; i++) p[i] = s[length-i]; printf("%s",p); The output of the pr...

easyanswer key
2004 PYQ

Consider the following C program segment struct CellNode{ struct CellNode *leftChild; int element; struct CellNode *rightChild; }; int Dosomething (struct CellNode *ptr) { int valu...

easyanswer key
2004 PYQ

Consider the following C function: int f(int n) { static int i = 1; if(n>=5) return n; n = n+1; i++; return f(n); } The value returned by f(1) is

easyanswer key
2004 PYQ

What does the following algorithm approximate? (Assume m > 1, $$ \in > 0$$) x = m; y = 1; while(x - y > ε){ x = (x + y) / 2; y = m/x; } print(x);

mediumanswer keyelite explanation
2003 PYQ

Consider the function f defined below. struct item { int data; struct item * next; }; int f(struct item *p) { return ((p == NULL) || (p ->next == NULL) || ((p->data <= p -> next ->...

easyanswer key
2003 PYQ

Assume the following C variable declaration int * A[10], B[10][10]; Of the following expressions I. A[2] II. A[2] [3] III. B[1] IV. B[2] [3] Which will not give compile-time errors...

mediumanswer key
2003 PYQ

Consider the C program shown below. #include < stdio.h > #define print(x) printf("%d ", x) int x; void Q(int z) { z += x; print(z); } void P(int *y) { int x = *y+2; Q(x); *y = x-1;...

mediumanswer key
2003 PYQ

Consider the following C function. float f,(float x, int y) { float p, s; int i; for (s=1,p=1,i=1; i < y; i++) { p *= x/i; s+=p; } return s; } For large values of y, the return val...

mediumanswer key
2001 PYQ

Consider the following C program: void abc(char *s) { if(s[0]=='\0') return; abc(s+1); abc(s+1); printf("%c",s[0]); } main() { abc("123"); } (a) What will be the output of the prog...

medium
2001 PYQ

Consider the following three C functions: [P1] int*g(void) { int x=10; return(&x); } [P2] int*g(void) { int *px; *px = 10; return px; } [P3] int*g(void) { int *px px =(int*)malloc...

easyanswer key
2000 PYQ

The value of j at the end of the execution of the following C program int incr (int i) { static int count = 0; count = count + i; return (count); } main () { int i,j; for (i = 0; i...

easyanswer key
2000 PYQ

The most appropriate matching for the following pairs X: m=malloc(5); m= NULL; Y: free(n); n->value = 5; Z: char *p; *p='a'; 1: using dangling 2: using uninitialized pointers 3. lo...

easyanswer key