The GATE Grind

GATE Programming and Data Structures: Programming in C – Previous Year Questions

68 GATE previous year questions on Programming in C (Programming and Data Structures, Computer Science) with answers and explanations, from every paper.

68 questions worth 106 marks in all (30 1-mark, 38 2-mark). Asked between 2008 and 2026, so you can see how the topic has been tested over time.

  1. GATE 2008 CS Q18 (1 mark, Multiple choice) – Which values make a=4?
  2. GATE 2008 CS Q60 (2 marks, Multiple choice) – What is printed by this C program?
  3. GATE 2008 CS Q84 (2 marks, Multiple choice) – The following erroneous C program attempts binary search in Y[10]: On which input does it fail?
  4. GATE 2008 CS Q85 (2 marks, Multiple choice) – The following erroneous C program attempts binary search in Y[10]: Which correction makes it work properly?
  5. GATE 2015 CS (CS3) Q11 (1 mark, Multiple choice) – What is printed?
  6. GATE 2015 CS (CS3) Q42 (2 marks, Numerical answer) – What is printed?
  7. GATE 2015 CS (CS3) Q43 (2 marks, Numerical answer) – What is printed?
  8. GATE 2015 CS (CS3) Q53 (2 marks, Numerical answer) – How many times is printf executed?
  9. GATE 2015 CS (CS2) Q52 (2 marks, Numerical answer) – What does this C program print?
  10. GATE 2010 CS Q21 (1 mark, Multiple choice) – What is printed?
  11. GATE 2011 CS Q32 (1 mark, Multiple choice) – What is printed?
  12. GATE 2013 CS Q60 (2 marks, Multiple choice) – A has length five; oldc,newc each have length three. The intended operation replaces each original A character at most once using the corresponding…
  13. GATE 2013 CS Q61 (2 marks, Multiple choice) – A has length five; oldc,newc each have length three. The intended operation replaces each original A character at most once using the corresponding…
  14. GATE 2012 CS Q13 (1 mark, MTA) – Find the output of the printed C fragment. Several case labels below retain the source’s semicolons.
  15. GATE 2012 CS Q58 (2 marks, Multiple choice) – What are the three output lines?
  16. GATE 2012 CS Q59 (2 marks, Multiple choice) – For the same complete code below, replace Line 1 with auto int a=1 and Line 2 with register int a=2. What are the three output lines?
  17. GATE 2017 CS (CS2) Q12 (1 mark, Multiple choice) – Match (P) static char var; (Q) m = malloc(10); m = NULL; (R) char *ptr[10]; (S) register int var1; with (i) sequence of memory locations storing…
  18. GATE 2017 CS (CS2) Q24 (1 mark, Multiple choice) – What is printed by printxy(1,1)?
  19. GATE 2017 CS (CS2) Q47 (2 marks, Multiple choice) – The following fragment divides x by y using repeated subtraction. All variables x,y,q,r are unsigned int. Which precondition ensures termination with…
  20. GATE 2017 CS (CS2) Q53 (2 marks, Numerical answer) – swap exchanges its two arguments. Find the output.
  21. GATE 2017 CS (CS2) Q64 (2 marks, Numerical answer) – Find the C program output.
  22. GATE 2017 CS (CS2) Q65 (2 marks, Numerical answer) – Find the C program output.
  23. GATE 2016 CS (CS2) Q22 (1 mark, Numerical answer) – What does this C program print?
  24. GATE 2016 CS (CS2) Q45 (2 marks, Multiple choice) – This function computes XY for positive integers. Which invariant holds before every loop iteration?
  25. GATE 2014 CS (CS2) Q20 (1 mark, Numerical answer) – For the C function below, find func(435). int func(int num) int count = 0; while (num) count++; num >>= 1; return count;
  26. GATE 2014 CS (CS2) Q21 (1 mark, Multiple choice) – n and p are unsigned int in C. To set p to n choose 3 for large n, which is most likely correct?
  27. GATE 2014 CS (CS1) Q20 (1 mark, Multiple choice) – Consider this C program: #include <stdio.h> main() int i; int *pi = &i; scanf("%d", pi); printf("%d", i+5); Which statement is TRUE?
  28. GATE 2017 CS (CS1) Q23 (1 mark, Multiple choice) – Consider the following C code: The code suffers from which one of the following problems:
  29. GATE 2017 CS (CS1) Q63 (2 marks, Numerical answer) – Consider the following C program. Recall that `strlen` is defined in `string.h` as returning a value of type `size t`, which is an `unsigned int`. The…
  30. GATE 2017 CS (CS1) Q65 (2 marks, Numerical answer) – The output of executing the following C program is .
  31. GATE 2016 CS (CS1) Q22 (1 mark, Multiple choice) – Consider the following C program. Which one of the following expressions, when placed in the blank above, will NOT result in a type checking error?
  32. GATE 2016 CS (CS1) Q25 (1 mark, Numerical answer) – Consider the following C program. The output of the program is .
  33. GATE 2016 CS (CS1) Q46 (2 marks, Multiple choice) – What will be the output of the following pseudo-code when parameters are passed by reference and dynamic scoping is assumed?
  34. GATE 2015 CS (CS1) Q16 (1 mark, Multiple choice) – Match the following: (P) Condition coverage (Q) Equivalence class partitioning (R) Volume testing (S) Alpha testing (i) Black-box testing (ii) System…
  35. GATE 2015 CS (CS1) Q34 (1 mark, Numerical answer) – The output of the following C program is .
  36. GATE 2015 CS (CS1) Q38 (2 marks, Numerical answer) – Consider the following C program segment. The cyclomatic complexity of the program segment is .
  37. GATE 2015 CS (CS1) Q62 (2 marks, Multiple choice) – 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.
  38. GATE 2015 CS (CS1) Q65 (2 marks, Multiple choice) – Consider the following pseudo code, where x and y are positive integers. The post condition that needs to be satisfied after the program terminates is
  39. GATE 2018 CS Q12 (1 mark, Multiple choice) – Consider the following C program. The output of this program is:
  40. GATE 2018 CS Q39 (2 marks, Multiple choice) – Consider the following C program: The output of the program above is
  41. GATE 2018 CS Q42 (2 marks, Multiple choice) – Consider the following C code. Assume that `unsigned long int` type length is 64 bits. The value returned when we call `fun` with the input 240 is
  42. GATE 2019 CS Q28 (1 mark, Numerical answer) – Consider the following C program: The value printed by the program is .
  43. GATE 2019 CS Q37 (2 marks, Multiple choice) – Consider the following C program: Which one of the following values will be displayed on execution of the programs?
  44. GATE 2019 CS Q62 (2 marks, Numerical answer) – Consider the following C program: The number of times the variable sum will be printed, when the above program is executed, is .
  45. GATE 2019 CS Q63 (2 marks, Numerical answer) – Consider the following C program: The output of the above C program is .
  46. GATE 2026 CS (CS2) Q17 (1 mark, Multiple choice) – In the C runtime environment, which one of the following is stored in the heap?
  47. GATE 2026 CS (CS2) Q19 (1 mark, Multiple choice) – Consider the following three ANSI C programs, P1, P2, and P3. Which one of the following statements is true?
  48. GATE 2026 CS (CS2) Q60 (2 marks, Numerical answer) – Consider the following ANSI C program. The output of this program is . (answer in integer) Note: Assume that the program compiles and runs…
  49. GATE 2026 CS (CS1) Q34 (1 mark, Numerical answer) – Consider the following program in C: The output of the program is . (answer in integer)
  50. GATE 2025 CS (CS2) Q19 (1 mark, Multiple choice) – Consider the following C program: Which ONE of the following will be the output of the program?
  51. GATE 2025 CS (CS2) Q33 (1 mark, Numerical answer) – The output of the given C code segment is . (Answer in integer)
  52. GATE 2025 CS (CS2) Q62 (2 marks, Numerical answer) – Consider the following C program: The output of the above program is . (Answer in integer)
  53. GATE 2025 CS (CS2) Q63 (2 marks, Numerical answer) – Consider the following C program: The output of the given C program is . (Answer in integer)
  54. GATE 2025 CS (CS1) Q34 (1 mark, Numerical answer) – The output of the given C program is . (Answer in integer)
  55. GATE 2025 CS (CS1) Q63 (2 marks, Numerical answer) – Consider the following C program: The value printed by the given C program is . (Answer in integer)
  56. GATE 2024 CS (CS2) Q13 (1 mark, Multiple choice) – Consider the following C program. Assume parameters to a function are evaluated from right to left. Which one of the following options is the CORRECT…
  57. GATE 2024 CS (CS2) Q33 (1 mark, Multiple select) – Consider the following C function definition. Which of the following statements is/are TRUE?
  58. GATE 2024 CS (CS2) Q36 (2 marks, Multiple choice) – What is the output of the following C program?
  59. GATE 2024 CS (CS1) Q18 (1 mark, Multiple choice) – Consider the following C program: Which one of the following statements is CORRECT?
  60. GATE 2024 CS (CS1) Q48 (2 marks, Multiple select) – Consider the C function: Which of the following statements is/are TRUE about the above function?
  61. GATE 2023 CS Q35 (1 mark, Numerical answer) – The integer value printed by the ANSI-C program given below is .
  62. GATE 2022 CS Q21 (1 mark, Multiple choice) – What is printed by the following ANSI C program?
  63. GATE 2022 CS Q43 (2 marks, Multiple choice) – What is printed by the following ANSI C program?
  64. GATE 2022 CS Q44 (2 marks, Multiple choice) – What is printed by the following ANSI C program? ASCII: A–Z = 65–90, a–z = 97–122, '*' = 42, '+' = 43, '−' = 45.
  65. GATE 2021 CS (CS1) Q47 (2 marks, Multiple choice) – Consider the following ANSI C program. Which one of the following options is correct?
  66. GATE 2021 CS (CS1) Q58 (2 marks, Numerical answer) – Consider the following ANSI C function: Let Z be an array of 10 elements with Z[i]=1, for all i such that 0 i 9. The value returned by…
  67. GATE 2020 CS Q32 (1 mark, Numerical answer) – Consider the following C program. The output of the program is .
  68. GATE 2020 CS Q58 (2 marks, Numerical answer) – Consider the following C functions. The value returned by pp(3,4) is .