Table of Contents

75 Top C Interview Questions

INTERMEDIATE-LEVEL C INTERVIEW QUESTIONS

1. What is C language and why is it widely used?

C is a procedural, structured programming language used for system-level programming (OS kernels, compilers).
It is popular because it is fast, portable, and close to hardware.

2. What is a compiler?

A compiler converts human-readable C code → machine code.


3. Difference between variables and constants?

VariablesConstants
Value can changeValue cannot change
Declared with typeDeclared with const

4. What are data types in C? Explain primary types.

Primary types: int, float, double, char, void.
They define the type & size of stored data.


5. What is the use of printf() and scanf()?

printf() → prints output
scanf() → takes input


6. What is a keyword? List any five.

Reserved words used by compiler.
Examples: int, return, if, while, switch.

7. Difference between = and ==?

= → assignment
== → comparison


8. What is an operator? Types of operators?

Symbols that perform operations.
Types: Arithmetic, Logical, Relational, Bitwise, Assignment.


9. What is type casting?

Converting one data type into another.
Example:

 
float x = (float)5;

10. What are loops?

Used to repeat code.
Types: for, while, do-while.


11. Difference between break and continue.

break → exits loop
continue → skips iteration, continues loop


12. What is an array?

A collection of elements of same type in continuous memory.

13. How do you declare an array?

 
int arr[10];

14. What is a string in C?

A string is a char array terminated with \0.


15. What does sizeof() do?

Returns memory size of variable/type.


16. What are functions? Why used?

Functions are reusable code blocks for modularity.


17. Difference between call by value and call by reference.

  • Call by value → copy passed

  • Call by reference → address passed using pointer


18. What are header files?

Files that contain declarations, e.g., stdio.h.


19. What is the purpose of main()?

Entry point of every C program.

20. How do comments work in C?

Single-line: //
Multi-line: /* ... */


21. Why semicolons are required in C?

Mark the end of a statement.


22. What is an infinite loop?

A loop that runs forever.
Example:

 
while(1){}

23. What is the return statement?

Ends function & optionally returns value.


24. What is a pointer?

Variable that stores memory address of another variable.


25. What is a null pointer?

A pointer that points to nothing (value = NULL).

INTERMEDIATE-LEVEL C INTERVIEW QUESTIONS

26. What are storage classes?

Define the scope, lifetime, and visibility of variables.
Types: auto, static, extern, register.


27. Difference between auto, static, extern?

  • auto: Local (default)

  • static: Retains value between function calls

  • extern: Declares global variable from another file


28. What is recursion?

Function calling itself.
Used for factorial, Fibonacci, tree traversal.


29. What is pointer arithmetic?

Operations allowed: ++, --, +, -.
Pointer moves based on data size.


30. Array of pointers vs pointer to array.

  • Array of pointers: int *arr[5];

  • Pointer to array: int (*ptr)[5];


31. What is a structure?

User-defined datatype to group mixed data types.


32. Difference between structure and union.

In a union, only one member can keep value at a time.
Structures store all members simultaneously.


33. What is dynamic memory allocation?

Allocating memory at runtime using:
malloc(), calloc(), realloc(), free().


34. Explain malloc(), calloc(), realloc(), free().

  • malloc() → uninitialized memory

  • calloc() → zero-initialized memory

  • realloc() → resize memory

  • free() → release memory


35. What is dangling pointer?

Pointer pointing to freed memory.


36. What is segmentation fault?

Accessing unauthorized memory.


37. What is a function pointer?

Pointer pointing to a function.
Example:

 
int (*fp)(int,int);

38. Explain pass-by-reference using pointers.

Instead of value, address is passed → function modifies original variable.


39. What are macros?

Preprocessor replacements defined using #define.


40. What is preprocessor?

Handles directives like #include, #define, #ifdef.


41. What is typedef?

Creates alias names for types.

 
typedef int number;

42. Explain file handling in C.

Use of functions:
fopen(), fclose(), fprintf(), fscanf(), fgets().


43. Difference between text mode and binary mode.

  • Text mode: characters

  • Binary mode: raw bytes


44. What is pointer-to-pointer?

A pointer that stores address of another pointer.
Example:

 
int **ptr;

45. Why can’t we return arrays from a function?

Arrays cannot be returned by value; instead return pointer.


46. Difference between const char*, char const*, char* const?

  • const char* → constant data

  • char const* → constant data (same as above)

  • char* const → constant pointer


47. What is an enum?

User-defined numeric constants.

 
enum week {Mon, Tue};

48. Can we use break in nested loops?

Yes, but it breaks only one loop.


49. Use of volatile keyword?

Prevents compiler optimization for variables that change unexpectedly (e.g., hardware registers).


50. What is a memory leak?

Allocated memory not released via free().

ADVANCED-LEVEL C INTERVIEW QUESTIONS

51. Explain stack vs heap memory.

StackHeap
Automatic memoryDynamic memory
FastSlower
Managed by compilerManaged by programmer
Limited sizeLarge size

52. How does the C compiler translate code?

Steps:

  1. Preprocessing

  2. Compilation

  3. Assembly

  4. Linking


53. What is undefined behavior?

Code that the C standard does not define.
Example:

 
int x = 10; printf("%d %d", x, ++x); // UB

54. What are sequence points?

Points where all previous operations complete (e.g., end of expression, &&, ||).


55. Inline function vs macro?

Inline → type-safe, checked by compiler
Macro → text substitution, no type checking


56. What is pointer aliasing?

Multiple pointers referencing same memory.


57. Memory alignment and padding in structures?

Compiler adds padding to align data in memory for faster access.


58. Little endian vs big endian?

Little → LSB stored first
Big → MSB stored first


59. How does function calling work internally?

Stack frame stores:

  • return address

  • parameters

  • local variables

  • saved registers


60. Explain bitwise operations.

Operations on bits: AND, OR, XOR, NOT, shifts.


61. What are bit fields?

Allow storing multiple tiny values within a single struct.


62. Deep copy vs shallow copy?

Shallow copy → copies pointer, not data
Deep copy → copies actual data


63. Static vs dynamic binding?

C supports only static binding (compile-time).


64. What is race condition?

Two threads accessing shared data without synchronization.


65. What are setjmp() and longjmp()?

Used for non-local jumps (error handling).


66. Why is volatile important in embedded systems?

Used for hardware-mapped registers that change asynchronously.


67. How to prevent buffer overflow?

Use safe functions:
fgets(), snprintf(), bounds checking.


68. Difference between fork() and threads?

fork() → new process
Thread → lightweight execution inside same process


69. How does memcpy() work internally?

Copies memory byte-by-byte using pointer iteration.


70. How does linker resolve external symbols?

Matches undefined symbols with definitions across object files/libraries.


71. Stack overflow vs heap overflow?

Stack overflow → too many function calls
Heap overflow → buffer overflow in dynamic memory


72. How are const pointers stored?

Const affects pointer or data, but storage is same in memory.


73. What is memory fragmentation?

Free memory split into small pieces → allocation failure.


74. How does C handle function overloading?

C does NOT support function overloading.


75. Explain the entire compilation process.

  1. Preprocessor expands macros

  2. Compiler converts code → assembly

  3. Assembler → object file

  4. Linker → final executable

Scroll to Top