HeapCrash / Topics / C, memory and debugging

C, memory and debugging: interview prep

Interview questions, hands-on challenges and design rounds on embedded C, memory and debugging, plus the companies whose embedded roles lean on it.

Interview questions

Key points for each answer are in the app's question bank.

  1. Explain the difference between const int *p, int *const p and const int *const p.Basic
  2. What does volatile do? Give two embedded situations where you need it.Basic
  3. What does static mean on a local variable, a global variable and a function?Basic
  4. Why does a compiler add padding to structs? How do you minimise it?Intermediate
  5. Write a function that detects whether the CPU is little-endian.Basic
  6. Write a function to swap the byte order of a 32-bit value.Basic
  7. Write macros or inline functions to set, clear, toggle and test bit n of a register.Basic
  8. Count the set bits in a 32-bit integer. Give two approaches.Basic
  9. How do you check if an unsigned number is a power of two in one expression?Basic
  10. Reverse the bits of a byte efficiently.Intermediate
  11. Implement memcpy. Then explain how memmove differs and implement it.Intermediate
  12. Why is strcpy dangerous? What would you use instead?Basic
  13. What are dangling pointers, memory leaks and double frees? How do you prevent them in firmware?Basic
  14. Where do local variables, globals, static locals, string literals and malloc'd memory live?Basic
  15. What happens on an MCU between reset and main()?Intermediate
  16. Use function pointers to implement a table-driven state machine.Intermediate
  17. What's wrong with #define SQUARE(x) x*x? Fix it.Basic
  18. Compare inline functions and macros.Basic
  19. What does if (-1 < sizeof(int)) evaluate to, and why?Intermediate
  20. Give three examples of undefined behaviour in C that bite embedded code.Intermediate
  21. Implement a fixed-size circular buffer with put and get.Basic
  22. Reverse a singly linked list, then detect whether it has a loop.Intermediate
  23. When would you use a union in firmware, and what are the caveats?Intermediate
  24. Why are C bit-fields risky for mapping hardware registers?Intermediate
  25. What are .text, .data, .bss and .rodata, and what does a linker script do?Intermediate
  26. Explain extern and why you get multiple-definition linker errors.Basic
  27. Implement atoi with error handling for overflow and invalid characters.Intermediate
  28. Why is recursion usually avoided on microcontrollers?Intermediate
  29. How do hardware and software breakpoints differ?Intermediate
  30. A Cortex-M device hits a HardFault in the field. How do you find the cause?Advanced
  31. What's the size of a pointer on a 32-bit MCU, and what does sizeof return for an array passed to a function?Intermediate
  32. Code works at -O0 but fails at -O2. List the usual causes.Advanced

Hands-on challenges

Design rounds

Companies that emphasise it

Practise these with an AI interviewer that asks the follow-up.

Start practising