Skip to content

GATE CS Programming in C questions

Practise Programming in C questions for GATE CS. Explore official PYQs and original topic-wise quizzes, check answers and view available solutions. Free, no sign-in.

Subject, topic, year and type filter the full library. Match any choice within a filter, and all selected filter categories. Search, source and sort apply to this page.

20 on this page
Official PYQ2016Programming and Data StructuresProgramming in CMCQ · 1 mark
What will be the output of the following CC program? void count (int n) { static int d=1; printf ("%d",n); printf ("%d",d); d++; if (n>1) count (n-1); printf ("%d",d); } void main(){ count (3); }
Official PYQ2016Programming and Data StructuresProgramming in CMCQ · 1 mark
The following function computes the maximum value contained in an integer array P[ ]P[ \ ] of size nn (n>=1)(n>=1). 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 missing loop condition is:
Official PYQ2016Programming and Data StructuresProgramming in CNAT · 1 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 _________.
Official PYQ2016Programming and Data StructuresProgramming in CMCQ · 1 mark
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 , when placed in the blank above, will NOT result in a type checking error?
Official PYQ2016Programming and Data StructuresProgramming in CNAT · 1 mark
Consider 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: max⁡(x,y)\max (x, y) returns the maximum of xx and yy. The value printed by this program is ________.
Official PYQ2016Programming and Data StructuresProgramming in CMCQ · 1 mark
The following function computes XYX^{Y} for positive integers XX and YY. 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 is TRUE before every iteration of the loop?
Official PYQ2016Programming and Data StructuresProgramming in CNAT · 1 mark
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); }
Official PYQ2015Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the following pseudo code, where xx and yy are positive integers. begin q := 0 r := x while r ≥ y do begin r := r - y q := q + 1 end end The post condition that needs to be satisfied after the program terminates is
Official PYQ2015Programming and Data StructuresProgramming in CNAT · 1 mark
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); }
Official PYQ2015Programming and Data StructuresProgramming in CNAT · 1 mark
Consider 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;} The output of the program is ______.
Official PYQ2015Programming and Data StructuresProgramming in CNAT · 1 mark
Consider 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("\n%d", i+k); case 3: printf("\n%d", i+k); default: printf("\n%d", i+k); } } return 0; } The number of times printf statement is executed is _______.
Official PYQ2015Programming and Data StructuresProgramming in CNAT · 1 mark
Consider the following C program #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}; int **ptr = p; ptr++; printf("%d%d", ptr-p, **ptr); } The output of the program is _______.
Official PYQ2014Programming and Data StructuresProgramming in CMCQ · 1 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?
Official PYQ2014Programming and Data StructuresProgramming in CMCQ · 1 mark
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 is TRUE?
Official PYQ2014Programming and Data StructuresProgramming in CMCQ · 1 mark
Suppose nn and pp are unsigned int variables in a C program. We wish to set pp to nC3^nC_3. If nn is large, which one of the following statements is most likely to set pp correctly?
Official PYQ2013Programming and Data StructuresProgramming in CNAT · 1 mark
What is the return value of f(p,p)f(p,p), if the value of pp is initialized to 55 before the call? Note that the first parameter is passed by reference, whereas the second parameter is passed by value. int f (int &x, int c) { c = c - 1; if (c==0) return 1; x = x + 1; return f(x,c) * x; }
Official PYQ2012Programming and Data StructuresProgramming in CMCQ · 1 mark
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 prtFun(void) { static int a = 2; /* Line 2 */ int b = 1; a += ++b; printf(“ \n %d %d ”, a, b); } What output will be generated by the given code segment if: Line 1 is replaced by …
Official PYQ2012Programming and Data StructuresProgramming in CMCQ · 1 mark
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 prtFun(void) { static int a = 2; /* Line 2 */ int b = 1; a += ++b; printf(“ \n %d %d ”, a, b); } What output will be generated by the given code segment?
Official PYQ2012Programming and Data StructuresProgramming in CMCQ · 1 mark
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"); case 'D' : case 'E' : default : printf ("No Choice"); }
Official PYQ2011Programming and Data StructuresProgramming in CMCQ · 1 mark
What does the following fragment of C program print? char c[] = "GATE2011"; char *p = c; printf("%s", p + p[3] - p[1]);