C Interview Questions with Answers
C INTERVIEW QUESTIONS & ANSWERS
Below is a complete, end-to-end C Interview Questions with Answers guide — from basic → intermediate → advanced → system-level → tricky MCQs & coding.
✅ 1. C BASICS
Q1. What is C?
Answer:
C is a procedural, structured, compiled, middle-level programming language developed by Dennis Ritchie (1972) at Bell Labs.
Q2. Why is C called a middle-level language?
Answer:
Because it supports:
-
Low-level features (pointers, memory access)
-
High-level features (functions, loops, structures)
Q3. Features of C
-
Portable
-
Fast execution
-
Rich library
-
Pointer support
-
Structured programming
-
Modular code
Q4. Difference between Compiler and Interpreter
| Compiler | Interpreter |
|---|---|
| Translates entire program | Translates line by line |
| Faster execution | Slower |
| Errors shown after compile | Errors shown immediately |
Q5. Structure of a C Program
✅ 2. DATA TYPES & VARIABLES
Q6. Data types in C
-
Primary: int, float, char, double
-
Derived: array, pointer, structure
-
User-defined: struct, union, enum, typedef
-
Void
Q7. Size of data types (typical 64-bit)
| Type | Size |
|---|---|
| char | 1 byte |
| int | 4 bytes |
| float | 4 bytes |
| double | 8 bytes |
Q8. What is a variable?
Answer:
A named memory location used to store data.
Q9. Difference between local & global variables
| Local | Global |
|---|---|
| Declared inside function | Declared outside |
| Scope limited | Accessible everywhere |
| Stored in stack | Stored in data segment |
✅ 3. OPERATORS
Q10. Types of operators
-
Arithmetic
-
Relational
-
Logical
-
Bitwise
-
Assignment
-
Conditional (
?:) -
Increment / Decrement
Q11. Difference between = and ==
-
=→ assignment -
==→ comparison
Q12. What is operator precedence?
Answer:
It defines the order in which operators are evaluated.
Example:
✅ 4. CONTROL STATEMENTS
Q13. Conditional statements
-
if
-
if-else
-
else-if ladder
-
switch
Q14. Difference between if-else and switch
| if-else | switch |
|---|---|
| Complex conditions | Constant expressions only |
| Slower | Faster |
| Flexible | Cleaner |
Q15. Loop types
-
for
-
while
-
do-while
Q16. Difference between while & do-while
-
while → condition checked first
-
do-while → runs at least once
✅ 5. FUNCTIONS
Q17. What is a function?
Answer:
A block of code that performs a specific task.
Q18. Types of functions
-
Library functions
-
User-defined functions
Q19. Call by value vs Call by reference
| Call by Value | Call by Reference |
|---|---|
| Copy passed | Address passed |
| No change | Original changes |
Q20. What is recursion?
Answer:
Function calling itself.
✅ 6. ARRAYS & STRINGS
Q21. What is an array?
Answer:
Collection of similar data stored in contiguous memory.
Q22. Difference between array and pointer
| Array | Pointer |
|---|---|
| Fixed size | Dynamic |
| Name constant | Can change |
| Stores values | Stores address |
Q23. What is a string?
Answer:
Array of characters terminated by \0.
Q24. Difference between gets() and fgets()
-
gets()→ unsafe (removed) -
fgets()→ safe
✅ 7. POINTERS (VERY IMPORTANT)
Q25. What is a pointer?
Answer:
A variable that stores the address of another variable.
Q26. Pointer syntax
Q27. Types of pointers
-
Null pointer
-
Dangling pointer
-
Wild pointer
-
Void pointer
-
Function pointer
Q28. What is a NULL pointer?
Answer:
Pointer that points to nothing.
Q29. Difference between * and &
-
*→ value at address -
&→ address of variable
✅ 8. STRUCTURE & UNION
Q30. Structure
Q31. Structure vs Union
| Structure | Union |
|---|---|
| Separate memory | Shared memory |
| More memory | Less memory |
| Faster access | Slower |
Q32. typedef
Answer:
Creates alias for data types.
✅ 9. MEMORY MANAGEMENT
Q33. Memory areas in C
-
Stack
-
Heap
-
Data segment
-
Code segment
Q34. malloc vs calloc
| malloc | calloc |
|---|---|
| Garbage values | Initializes to zero |
| Faster | Slightly slower |
Q35. free()
Answer:
Releases dynamically allocated memory.
✅ 10. FILE HANDLING
Q36. File modes
-
r, w, a
-
r+, w+, a+
Q37. fopen()
Q38. fclose()
Closes file and frees resources.
✅ 11. PREPROCESSOR
Q39. Preprocessor directives
-
#include
-
#define
-
#undef
-
#ifdef
-
#ifndef
Q40. Macro vs Function
| Macro | Function |
|---|---|
| Faster | Slower |
| No type checking | Type safe |
| More memory | Less memory |
✅ 12. STORAGE CLASSES
Q41. Types
-
auto
-
static
-
extern
-
register
Q42. static keyword
-
Retains value
-
Local scope, global lifetime
✅ 13. ADVANCED / TRICKY QUESTIONS
Q43. What is volatile?
Answer:
Tells compiler variable can change anytime.
Q44. What is segmentation fault?
Answer:
Illegal memory access.
Q45. What is dangling pointer?
Answer:
Pointer pointing to freed memory.
Q46. What is sizeof?
Answer:
Compile-time operator.
Q47. Why main returns int?
Answer:
To indicate program execution status.
✅ 14. COMMON CODING QUESTIONS
Reverse a number
Palindrome
Fibonacci
Swap without third variable
✅ 15. INTERVIEW TIPS
✔ Always explain memory
✔ Draw diagrams for pointers
✔ Mention time & space complexity
✔ Write clean code
✔ Handle edge cases
