Last Minute Notes C Programming
With GATE just around the corner, this rapid revision covers the highest-yield C programming facts you need to recall instantly during the exam. Data types...
Quick Revision: Data Types, Operators, and Control Flow
With GATE just around the corner, this rapid revision covers the highest-yield C programming facts you need to recall instantly during the exam. Data types and their sizes on a 32-bit system: char is 1 byte, short is 2 bytes, int is 4 bytes, long is 4 bytes, long long is 8 bytes, float is 4 bytes, and double is 8 bytes. On 64-bit systems, long becomes 8 bytes. GATE questions sometimes specify the platform, so read the problem statement carefully.
Integer overflow is a silent but tested trap. A signed int holds values from negative 2 raised to 31 up to 2 raised to 31 minus 1. Adding 1 to INT_MAX results in undefined behaviour for signed integers. For unsigned integers, the arithmetic wraps around modulo 2 raised to the bit width.
Operator precedence quick summary from highest to lowest: parentheses and function call, unary operators (increment, decrement, address-of, dereference), multiplicative (multiply, divide, modulo), additive (plus, minus), shift (left shift, right shift), relational (less, greater, less-equal, greater-equal), equality (equal-equal, not-equal), bitwise AND, bitwise XOR, bitwise OR, logical AND, logical OR, conditional (ternary), assignment, and comma.
Control flow facts to memorise: a switch statement with no break falls through to the next case. The continue statement in a for loop jumps to the increment expression, not to the top of the loop body. The goto statement is legal in C and can jump forward or backward within the same function scope.
For loops, while loops, and do-while loops are interchangeable but do-while always executes the body at least once. GATE sometimes asks you to convert between loop types and predict iteration counts. Key formula: a for loop with initialisation i=0, condition i less than n, and increment i++ executes the body exactly n times.
Array and pointer equivalence: the expression a[i] is identical to *(a + i), and pointer arithmetic scales by the element size. A two-dimensional array int a[3][4] is stored in row-major order in C. Element a[i][j] is located at offset i multiplied by 4 plus j from the array base.
Memorise the output of classic C programs: the comma operator returns the value of the rightmost expression; the ternary operator has lower precedence than most arithmetic operators; and prefix increment changes the value before use while postfix increment changes it after. These distinctions account for several 1-mark questions each year.
Rapid Recall: Pointers, Strings, and Memory Functions
Pointers are the single most tested topic in GATE C programming. Here are the critical facts for last-minute revision. A null pointer holds the value zero and points to no valid memory location. Dereferencing a null pointer is undefined behaviour. A void pointer can hold the address of any data type but cannot be dereferenced directly; it must be cast to a concrete pointer type first.
Pointer arithmetic rules: adding an integer n to a pointer of type T advances the pointer by n times sizeof(T) bytes. Subtracting two pointers of the same type gives the number of elements between them, not the byte difference. Comparing pointers with less-than or greater-than is only defined when both pointers point into the same array or to one past the last element.
String functions summary: strlen returns the number of characters before the null terminator. strcpy copies including the null terminator; the destination must have enough space. strcat appends the source to the destination and adds a null terminator. strcmp returns zero if strings are equal, a negative value if the first string is lexicographically smaller, and a positive value otherwise. strncpy copies at most n characters and does not guarantee null termination if the source is longer than n.
Memory functions: memcpy copies n bytes and does not handle overlapping regions. memmove handles overlapping regions correctly. memset fills n bytes with a given value, often used to zero out a buffer.
Dynamic allocation checklist: always check if malloc returns NULL before using the pointer; always free every allocated block exactly once; never use a pointer after freeing it; never access memory beyond the allocated size. These rules directly map to common GATE error-identification questions.
Function pointers syntax: int (*fp)(int, int) declares fp as a pointer to a function taking two ints and returning an int. Assigning fp = add and calling fp(3, 4) invokes the add function. This pattern is used in callback mechanisms and is occasionally tested in GATE.
One last tip: when the question shows a recursive function, draw the recursion tree or write out the call stack explicitly. Count total calls, total additions, and return values carefully. Rushing these questions leads to arithmetic mistakes that cost easy marks.
Exam-Day Checklist for C Programming
This checklist consolidates the points most commonly responsible for lost marks in GATE C programming questions. Review each item the night before the exam and again on the morning of exam day.
First, verify your understanding of the difference between declaration and definition. A declaration tells the compiler the type and name; a definition also allocates storage. An extern variable declaration without an initialiser is a declaration only. Failing to distinguish these causes linker errors in multi-file program questions.
Second, know that the return type of main is int in standard C. Returning 0 conventionally signals success. GATE questions sometimes include non-standard main declarations and ask whether the code is valid according to the C standard.
Third, remember that arrays decay to pointers when passed to functions. Inside a function receiving int arr[], the expression sizeof(arr) gives the size of a pointer, not the size of the array. This is a classic trap in questions about array-processing functions.
Fourth, the order of evaluation of function arguments is unspecified in C. If a function call such as f(i++, i++) appears, the behaviour is undefined. Similarly, expressions like a[i] = i++ have undefined behaviour because i is modified and accessed without an intervening sequence point.
Fifth, floating-point comparison using the equality operator is unreliable due to rounding errors. GATE questions on floating-point topics sometimes ask you to identify whether two computed values are guaranteed to be equal.
Sixth, in a structure assignment such as s1 = s2, all fields including padding are copied. This is a deep copy for plain data fields but not for pointer fields; both structures will point to the same heap data after assignment.
Seventh, the sizeof operator is evaluated at compile time for most cases. sizeof(expression) does not actually evaluate the expression; it only inspects the type. This means sizeof(a++) does not increment a.
Finally, for any question you are unsure about, eliminate obviously wrong answers first, then apply the rules you know. Educated guessing with one-third negative marking requires that you be more than 50 percent confident before marking an answer in the objective section. Skipping a 1-mark question saves you from a one-third mark penalty.