C Language Fundamentals
Use this page to revise the C concepts firmware tests actually ask about — not a full language course.
Types and macros
Prefer stdint.h (uint8_t, int32_t). #define is textual; a function-like macro needs parentheses. const and volatile are different: volatile is for hardware and shared ISR data.
Pointers, arrays, structs
A pointer holds an address. Arrays decay to pointers. A struct groups fields; typedef names a type; union overlays storage; enum names integer constants. Alignment and padding exist.
Stack, heap, and UB
Stack frames hold locals; heap is malloc (often avoided on small MCUs). Undefined behaviour (buffer overflow, use-after-free, data races) is how firmware "works until it doesn't".
Data structures
Know array, queue/ring buffer, stack, and when a linked list is a bad idea in a tiny RAM device.
Starting Points
- Kernighan, B. W., & Ritchie, D. M. The C Programming Language (2nd ed.).
- Language & toolchain
- Data representation
Key Points
- You can choose a
stdint.htype for a register, a count, and a physical quantity. - You can explain pointer vs. array vs. struct field access.
- You can explain stack vs. heap and why
mallocis risky on a small MCU. - You can explain
volatilevs.const. - You can name a ring buffer as the usual ISR-to-main structure and why a linked list may be the wrong default.