⚙️ C Programming for Embedded Systems
A complete, interview-focused tutorial series — from Number Systems & Bitwise basics to MMIO, ISRs and State Machines. Built for students preparing for embedded systems jobs.
15
Modules
43
Chapters
200+
Code Examples
150+
Interview Q&A
Free
Forever
Why This Series?
C is the language of embedded systems. Whether you are working on microcontrollers, device drivers, RTOS, or BLE firmware — C is everywhere. This series starts from number systems and bits, then builds up to advanced topics like volatile, interrupt handlers, bit-fields, and memory-mapped I/O — exactly what is asked in embedded interviews at companies like Texas Instruments, STMicroelectronics, Qualcomm, and semiconductor startups. Every chapter has working code, memory diagrams, and interview questions with answers.
🔍 Topics Covered in This Series
Number Systems Bitwise Operators Pointers Memory Layout Structures & Unions Bit-Fields volatile const Macros & Preprocessor Dynamic Memory Function Pointers Linked Lists ISR MMIO Endianness Stack & Heap Storage Classes Type Casting stdint.h State Machines
🔢 Module 1 — Foundations: Number Systems & Data Representation
Chapter 1
01
Number Systems: Binary, Octal, Decimal & Hexadecimal
How computers represent numbers — the absolute starting point for any embedded engineer.
Beginner 🎯 High Interview Weight
Decimal system Binary base-2 Octal base-8 Hexadecimal base-16 Base conversions Binary to Hex shortcut Why Hex in embedded 0x prefix notation
💡 What you will learn: Convert between all number bases manually and in C. Understand why hex is used for register addresses, memory maps, and bitmasks.
Interview Q: Convert 0xAF to binary. What is 255 in hex? Why do embedded engineers prefer hex over decimal for addresses?
Chapter 2
02
Signed Numbers: Sign-Magnitude, 1’s Complement & 2’s Complement
How negative numbers are stored in hardware — critical for understanding overflow and integer bugs.
Beginner 🎯 High Interview Weight
Sign-magnitude 1’s complement 2’s complement Why 2’s complement is used Range of signed types Integer overflow Signed vs unsigned in C
Interview Q: What is -1 in 2’s complement for 8-bit? What happens when you assign -1 to an unsigned char?
Chapter 3
03
Floating Point Representation: IEEE 754
How float and double are stored — and why you must never compare floats with == in embedded code.
Intermediate
IEEE 754 single precision IEEE 754 double precision Sign exponent mantissa NaN and Infinity Float precision issues Avoid float on MCU without FPU
Chapter 4
04
Endianness: Big Endian vs Little Endian
One of the most frequently asked embedded topics — how multi-byte data is stored in memory.
Intermediate 🎯 High Interview Weight
Big endian Little endian Network byte order Detecting endianness in C Endian swap with unions ARM vs x86
Interview Q: Write a C program to detect if the system is big or little endian. How does endianness affect serial protocols?
⚡ Module 2 — Bitwise Operations & Bit Manipulation
Chapter 5
05
Bitwise Operators: AND, OR, XOR, NOT, Left Shift, Right Shift
The heartbeat of embedded programming. Registers, flags, and hardware control all depend on bitwise ops.
Beginner 🎯 High Interview Weight
& AND operator | OR operator ^ XOR operator ~ NOT operator << left shift >> right shift Shift as multiply/divide Operator precedence
Interview Q: What is x & (x-1)? What does x ^ x give? Explain left shift as multiplication by power of 2.
Chapter 6
06
Bit Manipulation: Set, Clear, Toggle & Check a Bit
The daily toolkit — controlling GPIO pins, reading status registers, writing control words.
Beginner 🎯 High Interview Weight
Set a bit Clear a bit Toggle a bit Check a bit Bitmask macros Register flag patterns Count set bits popcount Find MSB LSB
Interview Q: Write a macro to set bit N of a register. Check if a number is power of 2 using bitwise. Swap two numbers without a temp variable.
Chapter 7
07
Bit Fields in Structures
Pack multiple flags into a single byte — used in protocol headers, register maps, and configuration structs.
Intermediate 🎯 High Interview Weight
Bit-field syntax Bit-field in struct sizeof bit-field struct Signed vs unsigned bit-field Padding in bit-fields Register struct example Portability concerns
Interview Q: How are bit-fields laid out in memory? Are they portable across compilers? When to use bit-fields vs bitmasks?
🏗️ Module 3 — C Language Basics
Chapter 8
08
Data Types, Variables & Constants in C
Choosing the right data type is critical in embedded — wrong types cause subtle bugs and portability issues.
Beginner
char int short longfloat doublesigned vs unsignedsizeof operator#define constantsconst keyworduint8_t uint32_t stdint.h
Interview Q: Why use uint8_t instead of unsigned char? What is size of int on 32-bit ARM? Difference between const int and #define?
Chapter 9
09
Operators & Expressions in C
Arithmetic, relational, logical operators — with special attention to pitfalls in embedded code.
Beginner
Arithmetic operatorsRelational operatorsLogical operatorsTernary operatorOperator precedence tableInteger promotion rules
Chapter 10
10
Type Casting & Type Conversion
Implicit and explicit casting — a major source of bugs when register values are misinterpreted.
Intermediate🎯 High Interview Weight
Implicit conversionExplicit castTruncation and sign extensionCasting pointersvoid* castingCommon casting bugs
Interview Q: What happens when you cast uint32_t to uint8_t? What is sign extension? When is (void*) cast used?
Chapter 11
11
Control Flow: if, else, switch, for, while, do-while
Flow control with embedded-specific patterns — polling loops, state machines, and avoiding deep nesting.
Beginner
if else if elseswitch-case fall-throughfor loopwhile loopdo-while loopbreak and continuegoto in embeddedInfinite loop patterns
🔧 Module 4 — Functions
Chapter 12
12
Functions: Declaration, Definition, Call by Value & Reference
Writing clean modular firmware. Call by value vs pointer, return types, scope.
Beginner
Function prototypeCall by valueCall by reference via pointerReturn typesVariable scope
Chapter 13
13
Recursion in C
Understanding recursion — and why embedded engineers avoid it due to stack overflow risk on limited RAM.
Intermediate
Base case and recursive caseStack frame per callTail recursionRecursion vs iterationWhy avoid on MCU
Chapter 14
14
inline Functions & static Functions
inline eliminates call overhead. static limits visibility to a single translation unit.
Intermediate🎯 High Interview Weight
inline keywordinline vs macrostatic functionFile scope with static
Interview Q: Difference between inline function and macro? When would you use static on a function?
📚 Module 5 — Arrays & Strings
Chapter 15
15
Arrays in C: 1D, 2D & Multi-dimensional
Contiguous memory blocks — essential for buffers, lookup tables, and DMA transfers.
Beginner
1D array declarationArray initializationNo bounds check in C2D arraysArray and pointer dualityconst arrays as lookup tables
Chapter 16
16
Strings in C: char Arrays & String Functions
Null-terminated char arrays — used for UART debug output, command parsers, and config strings.
Beginner
Null terminatorstrlen strcpy strcatstrcmp strncmpsprintf for UARTBuffer overflow danger
🎯 Module 6 — Pointers (Core Embedded Topic)
Chapter 17
17
Pointer Fundamentals: Declaration, Dereferencing & Arithmetic
Hardware registers ARE memory addresses — the most important C topic for embedded.
Intermediate🎯 High Interview Weight
Address-of &Dereferencing *Pointer arithmeticNULL pointerWild pointerDangling pointerPointer to pointer
Interview Q: What is a dangling pointer? How does pointer arithmetic work? Difference between NULL and 0?
Chapter 18
18
Pointers with Arrays & Strings
How arrays decay to pointers and how pointer notation is used for buffer operations.
Intermediate
Array name as pointerPointer vs arrayArray of pointerschar* vs char[]String traversal with pointer
Chapter 19
19
Function Pointers in C
Callbacks, dispatch tables, command parsers — used widely in RTOS and state machines.
Advanced🎯 High Interview Weight
Function pointer syntaxtypedef for function pointerCallbacksDispatch tableFunction pointer in struct
Interview Q: Declare a function pointer to a function taking int and returning int. How are function pointers used for ISR registration?
Chapter 20
20
const with Pointers: const int*, int* const, const int* const
Most confusing but frequently asked — understanding const placement prevents accidental data corruption.
Advanced🎯 High Interview Weight
Pointer to const intConst pointer to intRead from right ruleconst for ROM data
Interview Q: Difference between const int *p and int * const p? How do you read complex pointer declarations?
🧱 Module 7 — Structures, Unions & Enumerations
Chapter 21
21
Structures in C: struct, Padding & Memory Alignment
Structs for packet headers, device configs, register maps. Padding affects size and DMA correctness.
Intermediate🎯 High Interview Weight
struct declarationNested structsPadding rules__attribute__((packed))sizeof structArrow operator ->typedef struct
Interview Q: Why does sizeof(struct) not equal sum of member sizes? What does __attribute__((packed)) do?
Chapter 22
22
Unions in C: Memory Sharing & Practical Uses
Overlapping memory — used for endian detection, type punning, and protocol frame parsing.
Intermediate🎯 High Interview Weight
union definition and sizeunion vs structType punningUnion for endian detectionUnion in protocol parsing
Interview Q: What is the size of a union with int and char? Write code to check endianness using union.
Chapter 23
23
Enumerations (enum) in C
Named constants for states, error codes, and GPIO identifiers in firmware.
Beginner
enum syntaxDefault and custom valuesenum for state machinesenum vs #definetypedef enum
💾 Module 8 — Memory Layout, Storage Classes & Key Keywords
Chapter 24
24
Memory Layout of a C Program: Stack, Heap, BSS, Data, Text
The most important system-level topic for embedded interviews. Every variable lives in a specific region.
Intermediate🎯 High Interview Weight
Text segmentData segment initializedBSS uninitializedStack local varsHeap dynamic memoryMCU vs Linux memory mapStack overflow
Interview Q: Where does a global variable go? Where does a local variable go? What is BSS? What happens on stack overflow in embedded?
Chapter 25
25
Storage Classes: auto, static, extern, register
Control lifetime and scope — static and extern are critical for multi-file embedded projects.
Intermediate🎯 High Interview Weight
auto default localstatic local variablestatic global variableextern variableLifetime vs scope
Interview Q: Difference between static local and static global? What does extern do? Why use static on a global in embedded?
Chapter 26
26
volatile Keyword — The Embedded Engineer’s Best Friend
Without volatile, the compiler optimizes away hardware register reads — causing silent bugs in firmware.
Advanced🎯 High Interview Weight
What volatile doesCompiler optimization problemvolatile for MMIO registersvolatile for ISR shared varsvolatile const togethervolatile is NOT atomic
Interview Q: Why is volatile used with hardware registers? Does volatile guarantee atomicity? What is volatile const and where is it used?
Chapter 27
27
const Keyword: Variables, Pointers & Function Parameters
Protect data, place lookup tables in ROM/Flash, and write safer API interfaces.
Intermediate🎯 High Interview Weight
const variableconst vs #defineconst in function argsconst array as ROM tablevolatile const together
🔧 Module 9 — Preprocessor, Macros & Header Files
Chapter 28
28
C Preprocessor: #define, #include, #ifdef, #pragma
Controls conditional compilation, constants, and file inclusion — runs before compilation.
Intermediate🎯 High Interview Weight
#define constants#include guards#ifdef #ifndef #endif#pragma onceStringizing # operatorToken pasting ##Conditional compile for MCU target
Interview Q: Difference between #pragma once and include guard? How to conditionally compile for STM32 vs ESP32?
Chapter 29
29
Macros in C: Object-like, Function-like & Pitfalls
Powerful but dangerous — learn the rules for safe macros and when to prefer inline functions.
Intermediate🎯 High Interview Weight
Object-like macrosFunction-like macrosMacro side effects bugdo while(0) patternMAX MIN safe macrosMacro vs inline function
Interview Q: Why is #define MAX(a,b) dangerous without parentheses? Explain the do-while(0) macro idiom.
🔄 Module 10 — Dynamic Memory | 📂 Module 11 — File I/O
Chapter 30
30
malloc, calloc, realloc, free — Heap Memory in C
Dynamic memory is risky — leaks, fragmentation, and double-free crashes are common embedded bugs.
Intermediate🎯 High Interview Weight
malloc and NULL checkcalloc zero-initializedreallocfree and set to NULLMemory leaksDouble-free bugWhy avoid malloc on MCU
Interview Q: Difference between malloc and calloc? Why avoid dynamic allocation in safety-critical embedded systems?
Chapter 31
31
File I/O: fopen, fread, fwrite, fprintf, fseek, fclose
Config files, firmware images, log files — used in Linux-based embedded systems and host tools.
Intermediate
fopen modes r w a rb wbfprintf fscanffread fwritefseek ftell rewindBinary vs text modeferror and EOF handling
🔗 Module 12 — Data Structures in C for Embedded
Chapter 32
32
Linked Lists in C: Singly & Doubly Linked
OS task lists, event queues, and dynamic buffer management. Must-know for RTOS interviews.
Intermediate🎯 High Interview Weight
Node struct with pointerInsert at head tailDelete a nodeDoubly linked listCircular linked listReverse a linked list
Chapter 33
33
Stack & Queue: Array-based & Ring Buffer Implementation
RTOS message passing, UART ring buffers, and call stack tracing.
Intermediate🎯 High Interview Weight
Stack using arrayPush pop peekCircular ring bufferRing buffer for UARTQueue with linked list
Interview Q: Implement a circular buffer in C. Why is a ring buffer used for UART receive?
⚙️ Module 13 — Embedded C Specifics
Chapter 34
34
Memory-Mapped I/O (MMIO) in C
Peripherals accessed by reading/writing specific memory addresses — the foundation of all hardware drivers.
Advanced🎯 High Interview Weight
MMIO conceptDereferencing a fixed addressvolatile uint32_t* for registersGPIO register accessStruct overlay on peripheralARM Cortex register access
Interview Q: How do you write to a hardware register at address 0x40020000 in C? Why must the pointer be volatile?
Chapter 35
35
Interrupt Service Routines (ISR) in C
Write correct ISRs — keep them short, use volatile shared variables, no blocking calls.
Advanced🎯 High Interview Weight
ISR concept and purposeISR signaturevolatile flag from ISRKeep ISR short ruleNo blocking in ISRDisabling interrupts for atomicity
Interview Q: Why should ISRs be kept short? What type should a variable shared between ISR and main loop be?
Chapter 36
36
Fixed-Width Integer Types: stdint.h & Code Portability
uint8_t, int32_t — ensures identical behaviour on 8-bit, 16-bit, and 32-bit processors.
Intermediate🎯 High Interview Weight
uint8_t int8_tuint16_t int16_tuint32_t int32_tuintptr_tINT_MAX UINT8_MAXWhy int size varies
Chapter 37
37
State Machines in C — Core Embedded Design Pattern
Fundamental pattern for firmware — button debouncing, protocol handlers, motor control.
Advanced🎯 High Interview Weight
FSM conceptenum for statesswitch-case FSMFunction pointer FSMUART protocol parser FSM
📋 Module 14 — Advanced C Concepts
Chapter 38
38
typedef in C: Creating Type Aliases
Simplifies complex declarations — used extensively in HAL libraries and RTOS APIs.
Intermediate
typedef basicstypedef structtypedef for function pointertypedef vs #define
Chapter 39–41
39
Variadic Functions, Command Line Arguments & Error Handling
va_list internals, argc/argv parsing, errno and return code patterns for robust embedded software.
Advanced
va_list va_start va_arg va_endCustom debug loggerargc and argverrno perror strerrorassert() macroError code enum pattern
🎓 Module 15 — Interview Preparation Masterclass
Chapter 42
42
Top 50 C Interview Questions for Embedded Systems
Most frequently asked C questions at semiconductor companies — with detailed answers and code.
Advanced🎯 High Interview Weight
Pointers and memory Qsvolatile and const QsBitwise Qsstruct and union QsMemory layout QsISR and MMIO QsEndianness QsMacro pitfall Qs
Chapter 43
43
C Coding Problems for Embedded Interviews
Practical coding problems from written tests and technical rounds — all solved with embedded-style C code.
Advanced🎯 High Interview Weight
Endian check programCount set bitsSwap without tempReverse a stringCheck power of 2Implement memcpy memsetRing buffer implementationLinked list reversalGPIO toggle via MMIO
🚀 Start Learning C for Embedded Systems — Free!
Every tutorial is free, written by a practicing embedded engineer, and includes working C code examples plus interview Q&A. Start from Chapter 1 or jump to the topic you need.
▶ Start from Chapter 1 📋 View All Tutorials
Part of the EmbeddedPathashala free education initiative | Also see: BLE Audio Series | Linux System Programming
