Programming in C — GATE CS Previous Year Questions
Practise GATE CS previous year questions on Programming in C in Programming & Data Structures. Filter by year, marks and question type.
Public question previews
- Consider the following C statements: char *str1 = "Hello; /* Statement S1 */ char *str2 = "Hello;"; /* Statement S2 */ int *str3 = "Hello"; /* Statement S3 */ Which of the following options is/are correct? (2026 · 1 mark · MSQ)
- 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. (2026 · 1 mark · NAT)
- 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; struct node *next; }; int getListSize (struct node *head) { if( E1 ) return 1; return E2; } Which one of the following options gives the correct replacements for the expressions E1 and E2? (2026 · 2 marks · MCQ)
- 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. (2026 · 2 marks · NAT)
- The output of the given C program is __________. (Answer in integer) #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; } (2025 · 1 mark · NAT)