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 PYQ2026Programming and Data StructuresProgramming in CNAT · 1 mark
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, j = 10; func(i, j); return 0; } The output of the program is ______\_\_\_\_\_\_. (answer in integer) Note: Assume that the program compiles and runs successfully.
Official PYQ2026Programming and Data StructuresProgramming in CMCQ · 1 mark
In C runtime environment, which one of the following is stored in heap?
Official PYQ2026Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the following three ANSI-C programs, P1, P2,\text{P1, P2,} and P3\text{P3}. …
Official PYQ2026Programming and Data StructuresProgramming in CNAT · 2 marks
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.
Official PYQ2025Programming and Data StructuresProgramming in CNAT · 1 mark
#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\text{C} program is __________. (Answer in integer)
Official PYQ2025Programming and Data StructuresProgramming in CNAT · 2 marks
Consider 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; } The value printed by the …
Official PYQ2025Programming and Data StructuresProgramming in CNAT · 2 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 _________. (Answer in integer)
Official PYQ2025Programming and Data StructuresProgramming in CNAT · 2 marks
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<3; n++) sum += g(f(n)); printf ("%d", sum); return 0; } The output of the given C program is ___________. (Answer in integer)
Official PYQ2025Programming and Data StructuresProgramming in CMCQ · 1 mark
​​​​​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?
Official PYQ2025Programming and Data StructuresProgramming in CNAT · 1 mark
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)
Official PYQ2024Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the following C\mathrm{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?
Official PYQ2024Programming and Data StructuresProgramming in CMCQ · 1 mark
​​​Consider the following C\mathrm{C} program: #include <stdio.h> void fX (); int main(){ fX(); return 0 }; void fX () { char a; if ((a=g e t c h a r()) ! = '\n') fX(); if (a ! = '\n') putchar (a); } Assume that the input to the program from the command line is 12341234 followed by a newline character. Which one of the following statements is …
Official PYQ2024Programming and Data StructuresProgramming in CMSQ · 2 marks
​​Consider the following C\mathrm{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?
Official PYQ2024Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the following C\text{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 the following options is the CORRECT output of the …
Official PYQ2024Programming and Data StructuresProgramming in CMSQ · 1 mark
​​​Consider the following C\mathrm{C} function definition. int fX(char *a) { char *b = a; while (*b) b++; return b - a; } Which of the following statements is/are TRUE?
Official PYQ2024Programming and Data StructuresProgramming in CMCQ · 2 marks
​​​​​What is the output of the following C\text{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;}
Official PYQ2023Programming and Data StructuresProgramming in CNAT · 1 mark
The integer value printed by the ANSI-C\textsf{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\n", (x+y)); return 0; }
Official PYQ2022Programming and Data StructuresProgramming in CMCQ · 1 mark
What is printed by the following ANSI C\text{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; }
Official PYQ2022Programming and Data StructuresProgramming in CMCQ · 2 marks
What is printed by the following ANSI C\text{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\n”, c, d, e); return 0; } ASCII\text{ASCII} encoding for relevant characters is given below …
Official PYQ2021Programming and Data StructuresProgramming in CMCQ · 2 marks
​​​​​Consider the following ANSI C\text{ 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 following options is correct?