Quiz-Pointer Interview Questions for Embedded C: Quiz and Code Challenges-Free Embedded C Tutorial Online

Need Help or More Information?

Questions about this free C programming course, embedded C training or career guidance? Get in touch.

MODULE 9 · LESSON 9.1 · PRACTICE

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?

2. What does the expression &x give?

3. What does *p give, if p is an int *?

4. How big is a pointer on the STM32F407 (Cortex-M4)?

5. After int *a, b; the type of b is:

6. What is the value of a NULL pointer in a condition?

7. Reading 0x12345678 through a uint8_t * on a little-endian machine gives first:

8. Which statement dereferences an uninitialised pointer?

9. Which type is best for a pointer to a hardware register?

10. Two pointers hold the same address. A write through one:

11. What does p2 - p1 yield for two int * pointers into one array?

12. What is wrong with returning &local from a function?

13. What happens when you assign an int variable to an int * without a cast?

14. A function should accept optional output pointers. What should it check?

15. Which header defines NULL?

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:

2. Write a statement that stores the address of count in the int pointer ptr (assignment, not declaration):

3. Write a statement that sets the int that ptr points to the value 9:

4. int a = 3; int *p = &a; *p = *p + 4;. The value of a is

5. sizeof(uint32_t *) on the Cortex-M4 is bytes

6. The value 0xAABBCCDD read byte by byte (first byte) on a little-endian CPU is 0x

7. The base address of the STM32F407 SRAM is 0x

8. GPIOD ODR is at base 0x40020C00 plus offset 0x

Section 3: Which Term or Syntax Fits?

Choose the term or syntax for each description, as asked in pointer interview questions about fundamentals.

DescriptionYour answerResult
Get the address of x&x*pNULLvolatile uint32_t *p2 – p1wild pointerdangling pointeruint8_t *
Read the object p points to&x*pNULLvolatile uint32_t *p2 – p1wild pointerdangling pointeruint8_t *
A pointer that points nowhere&x*pNULLvolatile uint32_t *p2 – p1wild pointerdangling pointeruint8_t *
Pointer to a peripheral register&x*pNULLvolatile uint32_t *p2 – p1wild pointerdangling pointeruint8_t *
Distance between two pointers into an array&x*pNULLvolatile uint32_t *p2 – p1wild pointerdangling pointeruint8_t *
Pointer holding garbage&x*pNULLvolatile uint32_t *p2 – p1wild pointerdangling pointeruint8_t *
Pointer to freed or out-of-scope data&x*pNULLvolatile uint32_t *p2 – p1wild pointerdangling pointeruint8_t *
Examine an object byte by byte&x*pNULLvolatile uint32_t *p2 – p1wild pointerdangling pointeruint8_t *

Section 4: True or False

Statements typical of pointer interview questions.

1. A pointer must always point to an object of its declared type.

2. All pointer types have different sizes on one machine.

3. *p and &p are the same.

4. Dereferencing NULL is always a safe no-op.

5. if (p) is the same as if (p != NULL).

6. A function can change the caller’s variable if it receives its address.

7. Pointer subtraction gives a result in bytes.

8. The Cortex-M4 stores a 32-bit value least significant byte first.

Section 5: Code Snippet Challenges

Trace each program on paper first; the real output follows. These challenges are the code-reading half of pointer interview questions.

Challenge 1 — Output?: Two pointers to one variable
#include <stdio.h> int main(void) { int x = 5; int *p = &x; int *q = p; *q = *p + 3; printf(“%d %d\n”, x, *p); return 0; }

What is printed?

Output:
8 8
q and p both point to x. *q = *p + 3 writes 8 into x, so x and *p are 8.
Challenge 2 — Output?: Changing the pointer versus the target
#include <stdio.h> static void f(int *p) { p = NULL; } static void g(int *p) { *p = 0; } int main(void) { int v = 9; f(&v); printf(“%d “, v); g(&v); printf(“%d\n”, v); return 0; }

What is printed?

Output:
9 0
f assigns to its local copy of the pointer: v stays 9. g writes through the pointer: v becomes 0.
Challenge 3 — Output?: Bytes of a word
#include <stdio.h> #include <stdint.h> int main(void) { uint32_t w = 0x0A0B0C0Du; uint8_t *b = (uint8_t *)&w; printf(“%02X %02X %02X %02X\n”, b[0], b[1], b[2], b[3]); return 0; }

What is printed on a little-endian machine?

Output:
0D 0C 0B 0A
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); return 0; }

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); return 0; }

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); return 0; }

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+
OperatorApplied toResult
&xan objectits address (a pointer)
*pa pointerthe object it points to
*&xan objectx 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+
KindCauseExample
WildNever initialisedint *p; *p = 1;
DanglingObject has endedReturning &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+
type_iq.c
#include <stdio.h> #include <stdint.h> int main(void) { uint32_t w = 0xAABBCCDDu; printf(“%X %X %X\n”, (unsigned)*(uint8_t *)&w, (unsigned)*(uint16_t *)&w, (unsigned)*(uint32_t *)&w); return 0; }
Output (verified by compiling and running)
DD CCDD AABBCCDD

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+
reg_iq.c
#include <stdio.h> #include <stdint.h> static volatile uint32_t fake_odr; #define ODR (*(&fake_odr)) /* on the board: (*(volatile uint32_t *)0x40020C14UL) */ int main(void) { ODR |= 1u << 12; printf(“0x%X\n”, (unsigned)ODR); return 0; }
Output (verified by compiling and running)
0x1000

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

ScoreMeaningNext step
90–100%ExcellentContinue to Lesson 9.2: pointer arithmetic and arrays.
70–89%GoodRedo Examples 2, 3 and 6 of the examples page.
Below 70%ReviseRe-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.

Need Help or More Information?

Questions about this free C programming course, embedded C training or career guidance? Get in touch.

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *