Pointer Interview Questions for Embedded C: Quiz and Code Challenges
57 questions: multiple choice, write-the-statement blanks, a term-matching table, true/false, 6 code challenges with real output and 12 detailed interview answers. Treat it as a model for pointer interview questions.
57
Questions
Beginner → Advanced
Level
Live score
Auto-graded
Live Score Tracker
0 Correct
0 Wrong
0 Attempted
Answer the auto-graded questions (MCQ, fill-in, true/false) to see your score.
Section 1: Multiple Choice Questions — Pointers
These pointer interview questions appear in nearly every embedded C screening round. Click an answer; explanations always appear.
1. What does a pointer variable store?
The target object is reached by dereferencing.
2. What does the expression &x give?
Address-of operator.
3. What does *p give, if p is an int *?
Dereference.
4. How big is a pointer on the STM32F407 (Cortex-M4)?
A 32-bit address space needs 32-bit pointers.
5. After int *a, b; the type of b is:
The star applies to a only.
6. What is the value of a NULL pointer in a condition?
NULL compares equal to 0.
7. Reading 0x12345678 through a uint8_t * on a little-endian machine gives first:
The least significant byte is at the lowest address.
8. Which statement dereferences an uninitialised pointer?
p holds garbage; the write goes to a random address.
9. Which type is best for a pointer to a hardware register?
volatile forces every access.
10. Two pointers hold the same address. A write through one:
They alias the same object.
11. What does p2 - p1 yield for two int * pointers into one array?
Pointer subtraction counts elements (ptrdiff_t).
12. What is wrong with returning &local from a function?
The stack frame is reused.
13. What happens when you assign an int variable to an int * without a cast?
-Wint-conversion.
14. A function should accept optional output pointers. What should it check?
Writing through NULL is undefined behavior.
15. Which header defines NULL?
Also stdio.h and stdlib.h.
Section 2: Write or Evaluate (Fill in the Blanks)
Type the C line for the first three items (spacing is flexible) and a short value for the rest.
1. Declare p as a pointer to a uint32_t and initialise it to NULL:
Initialise at the declaration.
2. Write a statement that stores the address of count in the int pointer ptr (assignment, not declaration):
Use the address-of operator.
3. Write a statement that sets the int that ptr points to the value 9:
Dereference on the left of the assignment.
4. int a = 3; int *p = &a; *p = *p + 4;. The value of a is
Changed through p.
5. sizeof(uint32_t *) on the Cortex-M4 is bytes
Address width.
6. The value 0xAABBCCDD read byte by byte (first byte) on a little-endian CPU is 0x
Least significant byte first.
7. The base address of the STM32F407 SRAM is 0x
SRAM base.
8. GPIOD ODR is at base 0x40020C00 plus offset 0x
ODR offset.
Section 3: Which Term or Syntax Fits?
Choose the term or syntax for each description, as asked in pointer interview questions about fundamentals.
The least significant byte 0D comes first, then 0C, 0B, 0A.
Challenge 4 — Output?: Re-pointing a pointer
#include <stdio.h>int main(void)
{
int a = 1, b = 2;
int *p = &a;
int *q = &b;
p = q;
*p = 10;
printf(“%d %d\n”, a, b);
return0;
}
What is printed?
Output:
1 10
p = q makes p point to b; *p = 10 then changes b. a stays 1.
Challenge 5 — Find the bug: Returning the address of a local
#include <stdio.h>int *make(void)
{
int v = 7;
return &v;
}
int main(void)
{
int *p = make();
printf(“%d\n”, *p);
return0;
}
What does GCC report?
Compiler result:dangling.c: In function ‘make’:
dangling.c:5:12: warning: function returns address of local variable [-Wreturn-local-addr]
5 | return &v;
| ^~The local v no longer exists after make returns. Dereferencing p is undefined behavior.
Challenge 6 — Find the bug: The int *a, b trap
#include <stdio.h>int main(void)
{
int *a, b;
int v = 3;
a = &v;
b = &v;
printf(“%d\n”, *a + b);
return0;
}
What does GCC report?
Compiler result:trap.c: In function ‘main’:
trap.c:7:7: warning: assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast [-Wint-conversion]
7 | b = &v;
| ^Only a is a pointer. b = &v stores an address in an int. Declare int *a; int b; on separate lines.
Section 6: Pointer Interview Questions for Embedded C (with Detailed Answers)
Pointer interview questions test the address and dereference operators, pointer types, NULL, wild and dangling pointers, register access and aliasing. Click a question for a model answer.
Q1. What is a pointer and why do we need pointers?Basic+
A pointer is a variable that holds the address of another object. We need pointers to let functions modify the caller’s data, to work with arrays and strings without copying, to build linked data structures, to pass callbacks and to access memory-mapped hardware registers at fixed addresses.
Q2. Explain the difference between & and *.Basic+
Operator
Applied to
Result
&x
an object
its address (a pointer)
*p
a pointer
the object it points to
*&x
an object
x itself
In a declaration the star means “pointer to”.
Q3. What is the size of a pointer? Does it depend on the type?Basic+
The size depends on the machine’s address width, not on the type pointed to: 4 bytes on the STM32F407 (32-bit Cortex-M4), 8 bytes on a 64-bit PC. sizeof(char *) equals sizeof(double *). The pointed-to type affects how many bytes a dereference accesses and how pointer arithmetic scales (Lesson 9.2).
Q4. What is a NULL pointer and how do you use it?Basic+
NULL is the null pointer constant: it means “points to no object”. It compares equal to 0, is false in a condition and must never be dereferenced. Use it to initialise pointers, to signal failure from functions that return a pointer, and to mark unused slots (for example an unregistered callback). Check pointers received from outside before use.
Q5. What is a wild pointer and what is a dangling pointer?Intermediate+
Kind
Cause
Example
Wild
Never initialised
int *p; *p = 1;
Dangling
Object has ended
Returning &local, using memory after free
Both give undefined behavior. Prevent them by initialising at declaration, setting a pointer to NULL after freeing, and never returning the address of a local.
Q6. Why does the pointer type matter if all pointers have the same size?Intermediate+
The type fixes how many bytes a dereference reads or writes and how they are interpreted, and (Lesson 9.2) the step of pointer arithmetic. The same address read through different types gives different values.
Q7. How can a function return more than one value using pointers?Intermediate+
Pass the addresses of caller variables as output parameters and write through them; return a status code. Each output pointer can be optional (NULL means not wanted). See Lesson 8.2 for the full pattern, and use a struct when the results always belong together.
Q8. How do you access a hardware register with a pointer?Intermediate+
On the STM32F407: #define GPIOD_ODR (*(volatile uint32_t *)0x40020C14UL). The integer address is cast to a pointer to a volatile 32-bit object and dereferenced. volatile makes the compiler perform every read and write; the fixed-width type matches the 32-bit register.
Q9. What is the difference between a pointer to a variable and a pointer to a register?Advanced+
Syntactically none, but a register is volatile: its value can change without the program writing it (status bits), reads can have side effects (reading a data register clears a flag), writes may trigger actions, and some registers are write-only or write-1-to-clear. The compiler must therefore not cache, merge or drop accesses, so the pointer must be volatile, and code must use the right access width and read-modify-write rules.
Q10. Explain pointer aliasing and its effect on optimisation.Advanced+
Aliasing means two pointers may refer to the same object. Because a store through one can change what the other reads, the compiler must reload values after each store and cannot reorder or vectorise freely. The C99 restrict qualifier promises that no other pointer accesses the object during the pointer’s lifetime, allowing better code; breaking the promise is undefined behavior. The strict aliasing rule also forbids reading an object through a pointer of an unrelated type, except through character types.
Q11. Is it legal to compare pointers? Subtract them?Advanced+
Pointers into the same array (or one past its end) can be compared with relational operators and subtracted; the difference is the element count with type ptrdiff_t. Equality comparison is allowed for any two pointers. Relational comparison or subtraction of pointers to unrelated objects is undefined or unspecified in ISO C, although it works on flat-memory machines; use uintptr_t if you need to compare unrelated addresses, for example to test that a pointer lies in SRAM.
Q12. What happens if you dereference NULL on a Cortex-M4?Advanced+
The language says undefined behavior. On the STM32F407 address 0 is an alias of the memory selected by the BOOT pins (usually Flash at 0x08000000), so a read of NULL usually returns the first vector-table word without any fault, and the bug stays hidden. A write to Flash address 0 is silently ignored or raises a bus fault. Enable the MPU region at address 0 (no access) to turn NULL dereferences into faults during development.
Study Plan: Using Your Score on These Pointer Interview Questions
Score
Meaning
Next step
90–100%
Excellent
Continue to Lesson 9.2: pointer arithmetic and arrays.
70–89%
Good
Redo Examples 2, 3 and 6 of the examples page.
Below 70%
Revise
Re-read theory sections 2, 4 and 5, then retake the quiz.
Habit to build: Draw boxes and arrows for every pointer problem: one box per variable, an arrow for each pointer.
Lesson 9.1 complete!
Next up: pointer arithmetic and the close relationship between pointers and arrays.
2 Comments