Home › Blog › C programming interview questions with clear answers

C programming interview questions with clear answers

C interviews test whether you understand what your code does to memory. Expect pointers and pointer arithmetic, arrays versus pointers, dynamic allocation and leaks, storage classes and scope, structs, unions and padding, the preprocessor, and undefined behaviour. Embedded and systems roles go further into volatile, bit manipulation and memory-mapped I/O. Short code snippets with “what does this print?” are common, so trace carefully and say when behaviour is undefined.

Fifteen common C interview questions

  1. What is a pointer? What is a null pointer and a dangling pointer?
  2. What is the difference between an array and a pointer?
  3. Explain malloc, calloc, realloc and free.
  4. What is a memory leak, and how do you find one?
  5. What are the storage classes: auto, static, extern, register?
  6. What does static mean inside a function versus at file scope?
  7. Struct versus union?
  8. What is structure padding, and why does it happen?
  9. What does the volatile keyword do?
  10. What is undefined behaviour? Give examples.
  11. Macros versus inline functions?
  12. What does const mean in const int *p versus int *const p?
  13. How are arguments passed in C?
  14. What is a function pointer, and where is it used?
  15. How would you swap two variables, and what are the pitfalls of clever tricks?

Pointers and memory

Storage, structs and qualifiers

ConceptAnswer
static in a functionThe variable keeps its value between calls
static at file scopeLimits visibility to that file (internal linkage)
externDeclares a variable defined in another file
Struct vs unionMembers have separate storage vs members share the same storage
PaddingCompilers align members for efficient access, inserting unused bytes
volatileThe value may change outside the program's control, so don't optimise reads away
const int *pPointer to a constant int — can't change the value through p
int *const pConstant pointer — can't change where p points

Undefined behaviour

Undefined behaviour means the standard places no requirements on what happens, so the compiler may assume it never occurs and optimise accordingly. Common examples: dereferencing a null or dangling pointer, out-of-bounds array access, signed integer overflow, using an uninitialised variable, and modifying a variable twice without a sequence point (i = i++ + 1). In “what does this print?” questions, the correct answer to such code is that it's undefined — interviewers are often testing exactly that.

Bit manipulation basics

Systems and embedded interviews nearly always include a bit question. Know how to set a bit (x |= 1 << n), clear it (x &= ~(1 << n)), toggle it (x ^= 1 << n) and test it (x & (1 << n)); how to check for a power of two (x && !(x & (x - 1))); and why right-shifting a negative signed integer is implementation-defined. Counting set bits and reversing bits are common short coding tasks.

Macros, functions and passing arguments

C passes all arguments by value; to modify a caller's variable you pass its address. Macros are textual substitution by the preprocessor — no type checking, and arguments may be evaluated twice (a classic bug with SQUARE(i++)) — while inline functions are type-checked and evaluate arguments once. Function pointers enable callbacks, such as the comparison function passed to qsort, and dispatch tables in embedded systems. Embedded candidates should also see embedded software engineer questions.

Practising

The fastest way to find gaps is to be asked. Run a spoken mock round on C programming topics — a free AI interview assistant such as CoPilot Interview builds one from your résumé and the job description and scores every answer — then study whatever you stumbled on. Trace pointer snippets on paper with a box-and-arrow memory diagram; it prevents most mistakes. For C++ topics, see C++ interview questions.

Disclosure: CoPilot Interview is our product, so weigh what we say about it accordingly. Everything else on this page applies whichever tool you use, or none.

Frequently asked questions

What are the most common C interview questions?

Pointers, arrays versus pointers, dynamic memory allocation, memory leaks, storage classes, structs versus unions, padding, volatile, const placement, undefined behaviour, macros and function pointers.

What is the difference between malloc and calloc?

malloc allocates a block of uninitialised memory; calloc allocates memory for an array of elements and initialises every byte to zero.

What does volatile mean in C?

It tells the compiler that a variable's value may change outside the program's normal flow, such as a hardware register or a variable changed by an interrupt, so reads must not be optimised away.

What is undefined behaviour in C?

Code whose behaviour the C standard doesn't define, such as null dereferences, out-of-bounds access or signed overflow. The compiler may produce any result, including apparently working code.

Practise on real interview questions

Run 145 real interview questions across 10 tracks, answer out loud and see a structured answer to compare with yours. Free, no signup.

Try a practice question