Important Questions for C Exams
University C papers repeat the same topics every year: data types, operators, loops, arrays, functions, recursion, pointers, structures and files. If you prepare these questions well, a large part of the paper is already familiar.
This page is a question bank arranged unit-wise, with short-answer (2-mark) questions and long-answer (5 to 10-mark) questions. For each long question you get an answer outline, the points the examiner looks for, with links to the full lessons. At the end you'll find writing tips that earn extra marks.
What You Will Learn
- The most repeated C questions in university exams.
- Short-answer questions with model answers.
- Long-answer questions with the points to include.
- How to structure a long answer for full marks.
- Sample programs examiners commonly ask you to write.
Important Questions for C Exams Explained
How long answers are marked: examiners look for (1) a correct definition, (2) syntax, (3) a diagram or table where it helps, (4) a short example program with output, and (5) advantages/differences. Covering all five in a neat order usually gets full marks, even if the answer is not very long.
Memory trick: For any long answer, write "D-S-D-E-A": Definition, Syntax, Diagram, Example, Advantages. Five headings, five sets of marks.
Unit 1: Basics, Data Types and Operators
Short answer (2 marks)
- Define token. Name the types of tokens.
- The smallest unit of a C program: keywords, identifiers, constants, strings, operators and special symbols.
- What is the difference between a variable and a constant?
- A variable's value can change during execution; a constant's value cannot.
- What is the size and range of int and char?
- Usually int: 4 bytes (−2,147,483,648 to 2,147,483,647); char: 1 byte (−128 to 127 signed). Sizes depend on the compiler.
- What is type conversion?
- Changing a value from one type to another: implicit (automatic, e.g. int to float in mixed expressions) or explicit (typecasting, e.g.
(float)a). - What is operator precedence?
- The order in which operators are evaluated, e.g. * and / before + and −; associativity decides the order for equal precedence.
Long answer (5–10 marks)
- Explain the structure of a C program with an example. Outline: documentation section, preprocessor (link) section, definition section, global declarations,
main()with declarations and statements, user-defined functions; a labelled sample program. See Structure of a C Program. - Explain the data types in C. Outline: primary (int, char, float, double, void), derived (array, pointer, function), user-defined (struct, union, enum, typedef); a table of size, range and format specifier; modifiers.
- Explain the different types of operators with examples. Outline: arithmetic, relational, logical, assignment, increment/decrement, bitwise, conditional, special (sizeof, comma); one example each; precedence table.
Unit 2: Control Statements and Loops
Short answer (2 marks)
- Differentiate between while and do-while.
- while tests the condition first (entry-controlled, may run 0 times); do-while tests it after the body (exit-controlled, runs at least once).
- What is the use of break and continue?
- break exits a loop or switch; continue skips to the next iteration.
- What is the purpose of the goto statement?
- It jumps to a labelled statement; it makes code hard to follow, so it is avoided except to exit deeply nested loops.
Long answer (5–10 marks)
- Explain decision-making statements in C. Outline: if, if-else, nested if, else-if ladder, switch; syntax and a flowchart for each; example (grade calculation); comparison of switch and else-if.
- Explain looping statements with examples. Outline: for, while, do-while with syntax, flowcharts and examples; entry vs exit controlled; nested loops (pattern program); break/continue.
Unit 3: Arrays, Strings and Functions
Short answer (2 marks)
- What is an array? How is it initialised?
- A collection of same-type elements in contiguous memory, e.g.
int a[5] = {1, 2, 3, 4, 5}; - Why does a string end with '\0'?
- The null character marks the end, so functions like strlen and printf know where the string stops.
- Differentiate between call by value and call by reference.
- Call by value passes a copy (original unchanged); call by reference passes the address (original can change).
- What is recursion? Give its two conditions.
- A function calling itself; it needs a base case and a recursive case that moves towards the base case.
Long answer (5–10 marks)
- Explain one- and two-dimensional arrays with programs. Outline: declaration, initialisation, memory diagram, accessing elements; program for sum of array elements; matrix addition/multiplication program.
- Explain string handling functions with examples. Outline: strlen, strcpy, strcat, strcmp, strrev (non-standard), strupr/strlwr (non-standard); syntax, example and output of each; writing one without a library function.
- What is a function? Explain the types of user-defined functions. Outline: declaration (prototype), definition, call; four types by arguments and return value; advantages (reuse, modularity); example.
- Explain recursion with the factorial program and compare with iteration. Outline: definition, base case, recursion tree for 4!, program, comparison table (memory, speed, code size). See Recursion vs Iteration.
Example 1: Factorial Using Recursion (most asked program)
#include <stdio.h>
long factorial(int n)
{
if (n == 0 || n == 1) /* base case */
return 1;
return n * factorial(n - 1); /* recursive case */
}
int main(void)
{
int n;
for (n = 0; n <= 6; n++)
printf("%d! = %ld\n", n, factorial(n));
return 0;
}
Output
0! = 1 1! = 1 2! = 2 3! = 6 4! = 24 5! = 120 6! = 720
Code Explanation
- The base case (n is 0 or 1) returns 1 and stops the recursion.
- The recursive case multiplies n by the factorial of n − 1, so each call works on a smaller problem.
- For 4!: factorial(4) = 4 × factorial(3) = 4 × 3 × factorial(2) = 4 × 3 × 2 × factorial(1) = 24. Drawing this chain in the exam earns diagram marks.
Unit 4: Pointers, Structures and Unions
Short answer (2 marks)
- What is a pointer? Give its declaration.
- A variable that stores an address:
int *p = &x; - What is pointer arithmetic?
- Adding or subtracting integers to pointers; p + 1 moves to the next element (by sizeof the type).
- Differentiate between structure and union.
- Structure: separate memory for each member, size ≥ sum. Union: shared memory, size = largest member; one member valid at a time.
- What is dynamic memory allocation?
- Allocating memory at run time using malloc, calloc, realloc and freeing it with free.
Long answer (5–10 marks)
- Explain pointers and their uses with examples. Outline: definition, & and *, memory diagram, pointer arithmetic, pointers and arrays, call by reference (swap program), pointer to pointer, NULL pointer.
- Explain dynamic memory allocation functions. Outline: malloc, calloc, realloc, free with syntax and example; malloc vs calloc table; memory leak. See Dynamic Memory Allocation.
- Explain structures with an example. How is an array of structures used? Outline: definition, declaration, initialisation, member access (. and ->), array of structures (student records program), nested structures, structure vs union.
Unit 5: Files and Preprocessor
Short answer (2 marks)
- What is a file? Why do we need files?
- A named collection of data on secondary storage; files keep data permanently after the program ends.
- List the file opening modes.
- r, w, a, r+, w+, a+ (add b for binary).
- What is a macro?
- A name defined with #define that the preprocessor replaces before compilation.
- What are command line arguments?
- Values passed at run time, received in main as argc and argv.
Long answer (5–10 marks)
- Explain file handling functions in C. Outline: FILE pointer, fopen/fclose, fgetc/fputc, fgets/fputs, fprintf/fscanf, fread/fwrite, fseek/ftell/rewind; program to copy a file. See File Handling in C.
- Explain preprocessor directives. Outline: #include, #define (object and function macros), #undef, conditional compilation (#if, #ifdef, #ifndef), macro vs function table.
Example 2: Swap Using Call by Reference (Unit 4 favourite)
#include <stdio.h>
void swap_value(int a, int b)
{
int t = a; a = b; b = t;
}
void swap_reference(int *a, int *b)
{
int t = *a; *a = *b; *b = t;
}
int main(void)
{
int x = 10, y = 20;
swap_value(x, y);
printf("After call by value : x = %d, y = %d\n", x, y);
swap_reference(&x, &y);
printf("After call by reference: x = %d, y = %d\n", x, y);
return 0;
}
Output
After call by value : x = 10, y = 20 After call by reference: x = 20, y = 10
- One program shows both methods, which answers the "differentiate with an example" question completely.
- Call by value swaps copies, so x and y don't change. Call by reference swaps through pointers, so they do.
Important Points to Remember
- Use D-S-D-E-A for long answers: definition, syntax, diagram, example, advantages.
- Write programs with output; examiners award marks for the output too.
- Use tables for every "differentiate" question.
- Most repeated: loops, arrays, recursion, pointers, structure vs union, file handling.
- Draw memory diagrams for arrays and pointers and a recursion tree for factorial/Fibonacci.
- Manage time: attempt known questions first; never leave a question blank, write the definition at least.
Common Mistakes Beginners Make
| Mistake in exams | Better approach |
|---|---|
| Writing only theory for a long answer | Add syntax, an example program and its output |
| "Differences" written as paragraphs | Use a two-column table with 5–6 points |
| Programs without comments or output | Comment key lines; write a sample output box |
Using void main() and conio.h | Use int main(void) and standard headers |
| Spending too long on one question | Divide time by marks; move on and return later |
Exam Practice Questions
- Write the D-S-D-E-A outline for "Explain the for loop".
- List six differences between structure and union.
- Write a program to find the largest element of an array.
- Explain the four types of user-defined functions with one example each.
- What is the difference between a text file and a binary file?
Show answers
- Definition (entry-controlled loop for a known number of iterations), syntax (
for (init; condition; update)), flowchart, example (print 1 to 10 with output), advantages (compact, all control in one line). - Keyword (struct/union), memory (separate/shared), size (sum/largest), members active (all/one), initialisation (all members/first member), use (records/memory saving or variant data).
- Set max = a[0]; loop from index 1 and update max when a[i] > max; print max (see the next lesson for full programs).
- No arguments no return, arguments no return, no arguments with return, arguments with return; e.g. greet(), print_sum(a, b), read_number(), add(a, b).
- Text files store readable characters (newline conversions possible); binary files store raw bytes, compact and suited to fread/fwrite of structures.
Coding Exercise
A frequent 5-mark question: "Write a program to print the Fibonacci series using recursion." Print the first 10 terms.
Show solution
#include <stdio.h>
int fib(int n)
{
if (n <= 1)
return n; /* fib(0) = 0, fib(1) = 1 */
return fib(n - 1) + fib(n - 2);
}
int main(void)
{
int i;
printf("First 10 Fibonacci terms: ");
for (i = 0; i < 10; i++)
printf("%d ", fib(i));
printf("\n");
return 0;
}
First 10 Fibonacci terms: 0 1 1 2 3 5 8 13 21 34
Mention in your answer that this recursive version is slow for large n (it recomputes values), and an iterative loop is faster.
Quick Quiz: Exam Questions (MCQ)
-
The smallest individual unit of a C program is a:
A) Statement B) Token C) Function D) Byte
-
Which is a derived data type?
A) int B) char C) array D) float
-
A recursive function must have a:
A) Loop B) Base case C) Global variable D) Pointer
-
Which function frees dynamically allocated memory?
A) delete B) remove C) free D) clear
-
Which mode opens a file for appending?
A) "r" B) "w" C) "a" D) "x"
Show answers
- B: token.
- C: array.
- B: base case.
- C: free.
- C: "a".
Quick Revision for Exams and Interviews
Read this before your exam. The highlighted words are the answer.
Must-remember facts
| Long answer | D-S-D-E-A |
|---|---|
| Tokens | Keywords, identifiers, constants, strings, operators, symbols |
| while vs do-while | Entry vs exit controlled |
| Recursion | Base case + recursive case |
| Call by reference | Pass addresses; originals change |
| struct vs union | Separate vs shared memory |
| Files | Data kept permanently |
Frequently asked questions
- Which C topics are most important for university exams?
- Loops, arrays, strings, functions and recursion, pointers, structures vs unions and file handling.
- How do I write a long answer in a C exam?
- Follow definition, syntax, diagram, example program with output, advantages, using tables for differences.
- Should I write void main() in exams?
- No. Standard C uses int main(void) with return 0.
Remember
- Five headings, five sets of marks: D-S-D-E-A.
- Every program needs its output.
Next Topic
Next lesson: Important C Programs for Exams. You will practise the programs that appear most often in C exams and lab tests, with output.