C-CAT C Programming Revision: Topics and Traps
C programming for C-CAT: what to revise
C is the base of Section B. Most questions are short code snippets, so the skill being tested is tracing code correctly, not remembering definitions. This guide lists the topics worth revising, the rules behind them and the traps that appear again and again.
Topic checklist
| Topic | What to be able to do |
|---|---|
| Data types and sizes | State typical sizes, understand signed and unsigned, and implicit conversion |
| Operators | Apply precedence and associativity, and know that && and ` |
| Control flow | Trace nested loops, switch fall-through, break and continue |
| Functions | Pass by value, recursion tracing, function prototypes |
| Arrays | Index arithmetic, array-to-pointer decay, 2D arrays |
| Pointers | Pointer arithmetic, pointer to pointer, pointer to array, function pointers |
| Strings | Null terminator, strlen vs sizeof, common library functions |
| Storage classes | auto, static, extern, register and their lifetime and scope |
| Structures and unions | Memory layout, padding, size of a union |
| Dynamic memory | malloc, calloc, realloc, free, leaks and dangling pointers |
| Preprocessor | Macros with arguments, and why parentheses matter |
Pointers and arrays
Pointers are the single biggest source of C questions. Keep these rules in mind:
- Adding 1 to a pointer moves it by
sizeof(type)bytes, not by 1 byte. - For an array
a, the expressionadecays to a pointer to its first element in most contexts, soa[i]is the same as*(a + i). sizeof(a)on an array gives the total bytes, but once the array is passed to a function it becomes a pointer, sosizeofinside the function gives the pointer size.*p++increments the pointer after reading the value, because++binds before*in this expression, but the increment applies top, not to the value.- A pointer to
constdata and aconstpointer are different things:const int *pblocks changing*p, whileint *const pblocks changingp.
Detailed notes: Pointers in C.
Operators, precedence and short-circuit
Many output questions are decided by one precedence rule.
- Postfix
++and--bind tighter than unary*and&. &&has higher precedence than||.&&and||stop evaluating as soon as the result is known, so a side effect on the right side may never run.- Integer division truncates:
5 / 2is2, and-5 / 2is-2in C99 and later. - Modifying the same variable twice between sequence points, such as
i = i++ + ++i, is undefined behaviour. If a question asks for its output, the correct answer is usually “undefined” or “compiler dependent”.
Detailed notes: Operator precedence and Short-circuiting in C.
Storage classes
| Class | Scope | Lifetime | Default value |
|---|---|---|---|
auto | Block | Until the block ends | Garbage |
static (local) | Block | Whole program | 0 |
static (global) | File only | Whole program | 0 |
extern | Global across files | Whole program | 0 |
register | Block | Until the block ends | Garbage |
A static local variable is initialised only once, so a function that increments it keeps the count between calls. This is a favourite output question.
Detailed notes: Storage classes in C.
Strings
- A C string is a
chararray ending with'\0'. The array must have room for that extra byte. strlencounts characters before'\0'.sizeofon an array counts every byte, including the terminator.char s[] = "abc"creates a modifiable array.char *s = "abc"points to a string literal that must not be modified.strcmpreturns 0 when the strings are equal, not 1.
Detailed notes: Strings in C.
Structures, unions and memory
- The size of a structure can be larger than the sum of its members because of padding added for alignment.
- All members of a union share the same memory, so its size is the size of its largest member.
- Every
mallocneeds a matchingfree. Using memory afterfreeis a dangling pointer bug, and freeing twice is undefined behaviour. calloczero-initialises the memory, whilemallocdoes not.
Detailed notes: Dynamic memory allocation.
A 7-day revision plan
- Day 1: data types, operators, precedence.
- Day 2: control flow and functions, with recursion tracing.
- Day 3: arrays and pointers.
- Day 4: strings and pointer arithmetic practice.
- Day 5: storage classes, structures and unions.
- Day 6: dynamic memory and the preprocessor.
- Day 7: mixed output-prediction questions under a timer.
Practise and revise further
- C Programming Cheat Sheet for one-page revision
- C programming notes for detailed explanations
- C Programming for C-CAT: Concepts and Output Tracing for a step-by-step method to trace output questions
- C-CAT Section B Preparation Guide for the overall checklist
- C interview questions for extra practice
For the full section list, see the C-CAT syllabus.
Key takeaways
- Most C questions test code tracing, so practise by hand.
- Master pointers and precedence first; they decide the most questions.
- Know the static, extern and storage-class rules cold.
- Watch for undefined behaviour in “tricky” expressions.
Frequently Asked Questions
1 How many C programming questions come in C-CAT Section B?
C-DAC does not publish a topic-wise split, so no exact number can be promised. C is consistently one of the most tested subjects in Section B, and the questions are mostly output prediction and concept checks.
2 Which C topics should I revise first?
Start with pointers and arrays, then operators and precedence, storage classes, strings, structures, and dynamic memory. These cover most of the questions that are asked repeatedly.
3 Are C-CAT C questions code-based?
Yes, a large share ask you to predict the output of a short snippet or find the error in it. Practise tracing code by hand instead of only reading theory.
4 How long does it take to revise C for C-CAT?
If you already know the basics, 5 to 7 focused days with daily output-prediction practice is usually enough for a full revision. Beginners need longer.
5 What is the most common mistake in C output questions?
Ignoring operator precedence, integer division and pointer arithmetic. Write the value of every variable after each line instead of guessing the result.