C Programming Previous Year Questions
Studying previous year questions (PYQs) is the most effective strategy for GATE C programming preparation. Over the past decade, GATE has consistently test...
Analysis of GATE PYQs on C: Patterns and Approach
Studying previous year questions (PYQs) is the most effective strategy for GATE C programming preparation. Over the past decade, GATE has consistently tested five broad categories in C: pointer arithmetic and dereferencing, recursion and function calls, output tracing with operators, memory management, and string manipulation. Recognising which category a question belongs to lets you apply the right mental framework immediately.
Pointer questions most frequently appear as 1-mark multiple-choice items. A typical pattern: a short snippet declares a pointer, performs some arithmetic, and asks for the output of a printf statement. The key is to carefully track what each pointer points to after each assignment or arithmetic operation. Never assume; always compute the address arithmetically.
Recursion questions often appear as 2-mark items and ask for the return value of a recursive function given a specific input, the total number of times the function is called, or the depth of the recursion stack. The strategy is to expand the recursion manually for small input values or to identify the recurrence relation and solve it analytically. For example, if a function T(n) calls itself twice with input n minus 1 and adds 1, the recurrence is T(n) = 2T(n-1) + 1 with T(0) = 0, which solves to T(n) = 2 raised to n minus 1.
Output-tracing questions with operators test whether you know operator precedence and associativity rules cold. A frequently tested pattern involves the pre-increment and post-increment operators in the same expression. Example from a GATE-style question: int i = 5; printf("%d %d", i++, ++i). The output depends on the order of argument evaluation, which is unspecified. The correct GATE answer acknowledges the unspecified behaviour.
For 2025 and recent years, GATE has also included questions involving structures and unions, particularly asking for sizeof values with alignment considerations. Practice computing struct sizes by adding field sizes and padding manually.
Build a personal question bank organised by year and category. After solving each PYQ, write a one-line note about the key concept it tested. Reviewing these notes in the final week consolidates patterns more efficiently than re-reading theory chapters.
Worked Examples from Past GATE Papers
Working through representative GATE problems with full explanations builds the reasoning patterns you need to solve unseen questions quickly. This section presents several problem types with solution walkthroughs.
Problem type one: array pointer arithmetic. Consider int a[] = {10, 20, 30, 40}; int *p = a; printf("%d", *(p+2)); The pointer p initially holds the address of a[0]. Adding 2 to p moves it forward by 2 times sizeof(int) bytes, landing at a[2]. Dereferencing gives 30. This type of question should take under 30 seconds once the method is internalised.
Problem type two: recursive function. A function f(n) is defined as: if n equals 0 return 0; else return f(n-1) + n. What is f(4)? Expanding: f(4) calls f(3) + 4, f(3) calls f(2) + 3, f(2) calls f(1) + 2, f(1) calls f(0) + 1, f(0) returns 0. Backtracking: f(1) = 1, f(2) = 3, f(3) = 6, f(4) = 10. The function computes the sum of integers from 1 to n, which equals n(n+1)/2.
Problem type three: bitwise operations. What is the result of 13 & 10? In binary, 13 is 1101 and 10 is 1010. The AND operation gives 1000, which is 8 in decimal. Similarly, 13 | 10 gives 1111, which is 15. These can be computed without a calculator by converting to binary and applying the operation column by column.
Problem type four: struct size. Consider struct S { char a; int b; char c; }. The char a occupies 1 byte, then 3 bytes of padding are added so that int b starts at a 4-byte boundary. The int b occupies 4 bytes. The char c occupies 1 byte, then 3 bytes of tail padding bring the struct size to a multiple of 4. Total: 12 bytes. Many students incorrectly answer 6, missing the padding.
Problem type five: string length versus sizeof. Given char s[] = "GATE2025"; strlen(s) is 8 and sizeof(s) is 9 because the array stores the null terminator. If the declaration were char *s = "GATE2025"; then sizeof(s) would be 4 or 8 depending on pointer size, not 9.
Each of these problem types has appeared multiple times across GATE papers. Drilling them until the solution method is automatic is the key to scoring full marks in this section.
Time Management and Scoring Strategy for C Questions
GATE is a 3-hour exam with 65 questions worth 100 marks. C programming questions, whether standalone or embedded in algorithms questions, demand a disciplined time budget. For 1-mark C questions, allocate at most 90 seconds. For 2-mark questions, allow up to 3 minutes. If a question requires more time than this, flag it and return after completing the rest of the section.
The negative marking scheme is one-third of a mark for 1-mark questions and two-thirds of a mark for 2-mark questions. This means that random guessing on a 1-mark question has an expected value of zero only if you are choosing among 4 options with equal probability. In practice, you can almost always eliminate at least one option, which raises the expected value of an educated guess to positive territory.
A category of C questions that GATE aspirants frequently mismanage involves multi-line programs with tricky control flow. The temptation is to trace every variable through every iteration. A faster approach is to identify the invariant or pattern after the first two or three iterations and extrapolate. For a loop that runs 100 times, you do not need to trace all 100 iterations; find the pattern after iterations 1 and 2 and generalise.
For questions involving undefined behaviour, the GATE committee typically provides answer choices that include a specific value, all options, or "behaviour is undefined." If you recognise an undefined behaviour pattern such as modifying a variable twice between sequence points, mark "undefined" confidently rather than trying to compute a specific value.
After the exam, your C programming score is often the easiest section to improve through targeted PYQ practice. Unlike theory-heavy topics such as theory of computation, C programming rewards systematic practice of a relatively small set of patterns. Solving 100 to 150 PYQs on C, reviewing every mistake, and categorising errors by type (conceptual misunderstanding, arithmetic mistake, or careless reading) will typically add 3 to 5 marks to your total GATE score.
Invest time in learning to read C code as a sequence of memory operations rather than as instructions in a high-level language. This mental shift, from thinking about what the code "means" to thinking about what bytes are being written and read, is the difference between getting 2 out of 5 C questions right and getting all 5 right.