C Programming for C-CAT: Concepts and Output Tracing
C is the foundation of Section B. Data structures and OOP questions often include C-style code, so a strong grip on C pays off across the paper. This post covers the concepts that come up most and a reliable method for tracing code.
The concepts that appear most often
- Data types and sizes: int, char, float, double and how they convert in expressions.
- Operators: precedence and associativity, increment and decrement, bitwise and logical operators.
- Control flow: loops, switch with and without break, nested conditions.
- Functions: call by value, recursion, return types.
- Storage classes: auto, static, register, extern and the lifetime of variables.
- Arrays and strings: indexing, null terminator, string functions.
- Pointers: address-of, dereference, pointer arithmetic, pointers to pointers, arrays and pointers.
- Structures and unions: member access, size differences, arrays of structs.
- Dynamic memory: malloc, calloc, realloc, free and common leaks.
- Preprocessor: macros and their side effects.
Use our C cheat sheet and structures sheet for quick revision.
A four-step method for output questions
- List the variables and their initial values on paper.
- Execute one line at a time, updating the values.
- Watch the format specifiers. What gets printed depends on how it is printed.
- Check for undefined behaviour before answering.
Example 1: pointers
int a = 5;
int *p = &a;
printf("%d", *p + 1);
*p is 5, so the output is 6.
Example 2: array and pointer arithmetic
int arr[] = {10, 20, 30};
int *p = arr;
printf("%d", *(p + 2));
p + 2 moves two elements ahead, so the output is 30.
Example 3: static variables
void f() {
static int c = 0;
c++;
printf("%d ", c);
}
// calling f() three times prints: 1 2 3
A static variable keeps its value between calls.
Example 4: strings and sizeof
char s[] = "abc";
// strlen(s) is 3, sizeof(s) is 4 (includes the null terminator)
Undefined behaviour: do not guess a number
Some expressions have no defined answer, such as modifying the same variable twice with no sequence point between the changes, for example x++ + ++x. If an option says “undefined” or “compiler dependent”, that is often the intended answer. Do not invent an output.
Other traps include:
- Using
%dto print a float or%fto print an int. - Accessing an array out of bounds.
- Dereferencing a null or uninitialised pointer.
- Integer division: 7/2 is 3, not 3.5.
Practice plan
- Solve 10 output questions a day, tracing on paper first.
- After each wrong answer, write the rule you broke in your error log.
- Move to timed sets once accuracy is steady.
FAQ
Do I need to memorise library functions? Know the common string and memory functions and what they return.
Are pointer questions the hardest? Often yes, but drawing memory boxes makes them manageable.
Which book helps? A standard C text with many exercises, plus plenty of timed MCQs.