Pointer to Pointer Interview Questions for Embedded C: Quiz and Code Challenges
57 questions: multiple choice, write-the-declaration blanks, a concept-matching table, true/false, 6 code challenges with real output and 12 detailed interview answers. Treat it as a model for pointer to 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.
Only the two pointers are exchanged; the literals do not move.
Challenge 4 — Output?: void * round trip
#include <stdio.h>int main(void)
{
int v = 3;
void *vp = &v;
int *ip = vp;
*ip += 4;
printf(“%d %d\n”, v, sizeof(vp) == sizeof(ip));
return0;
}
What is printed?
Output:
7 1
The address survives the conversion to void * and back. v becomes 7; all object pointers have the same size here, so the comparison prints 1.
Challenge 5 — Find the bug: Dereferencing void *
#include <stdio.h>int main(void)
{
int v = 3;
void *vp = &v;
printf(“%d\n”, *vp);
return0;
}
What does GCC report?
Compiler result:voidstar.c: In function ‘main’:
voidstar.c:6:20: warning: dereferencing ‘void *’ pointer
6 | printf(“%d\n”, *vp);
| ^~~
voidstar.c:6:20: error: invalid use of void expressionThe compiler does not know the type behind a void *. Convert first: *(int *)vp.
Challenge 6 — Output?: Setting a pointer parameter to NULL
#include <stdio.h>staticvoid reset(int *p) { p = NULL; }
int main(void)
{
int v = 5;
int *p = &v;
reset(p);
printf(“%s\n”, p ? “still set” : “NULL”);
return0;
}
What is printed?
Output:
still set
reset clears its own copy. To clear the caller’s pointer the parameter must be int **.
Section 6: Pointer to Pointer Interview Questions for Embedded C (with Detailed Answers)
Pointer to pointer interview questions test double pointers, arrays of pointers, void pointers, NULL, wild and dangling pointers and allocation strategy. Click a question for a model answer.
Q1. What is a pointer to pointer and when do you use it?Basic+
A pointer to pointer (T **) holds the address of a T *. Use it when a function must change the caller’s pointer (advance a cursor, return a buffer address through a parameter, unlink a list node), for arrays of pointers (argv, string tables) and for functions that clear a pointer after freeing.
Q2. Why can a function not change the caller’s pointer with a single-star parameter?Basic+
pp_iq.c
#include <stdio.h>staticvoid bad(int *p, int *t) { p = t; }
staticvoid good(int **p, int *t) { *p = t; }
int main(void)
{
int a = 1, b = 2;
int *p = &a;
bad(p, &b);
printf(“%d “, *p);
good(&p, &b);
printf(“%d\n”, *p);
return0;
}
Output (verified by compiling and running)
1 2
C passes the pointer by value, so the function modifies its copy. Passing the pointer’s address lets it assign to the original.
Q3. What is a void pointer? What can and cannot you do with it?Basic+
Allowed
Not allowed (standard C)
Hold the address of any object
Dereference it
Convert to/from any object pointer without a cast (C)
Pointer arithmetic
Pass to memcpy, qsort, callbacks
Hold a function pointer portably
Compare with NULL or other pointers
GCC allows arithmetic on void * as an extension (step of 1 byte); standard code uses uint8_t *.
Q4. What is NULL and how do you handle it?Basic+
NULL is the null pointer constant: it points to no object, compares equal only to other null pointers and is false in a condition. Initialise unused pointers to it, return it from pointer-returning functions to signal failure, and test pointers received from outside before use. Never dereference it and never pass it to library functions that expect a valid object.
Q5. Explain the difference between a wild pointer and a dangling pointer.Intermediate+
A wild pointer was never initialised, so it holds an arbitrary value. A dangling pointer once pointed to a valid object that has since ended: a freed heap block, a local variable of a function that returned, or a buffer that was reallocated. Both lead to undefined behavior. Remedies: initialise at declaration, set to NULL after free, do not return addresses of locals, and prefer static storage or pools.
Q6. How does an array of pointers differ from a 2D array?Intermediate+
The 2D array stores all characters inline (3 × 7 = 21 bytes, rows padded). The array of pointers stores three addresses and the strings live separately (in Flash if literals); rows can differ in length and be swapped by exchanging pointers.
Q7. How would you write a generic function that works on arrays of any type?Intermediate+
Take void *base, an element size and a count; step with a uint8_t * cursor ((uint8_t *)base + i * size); move elements with memcpy or memmove; and take operations such as comparison as function-pointer callbacks that receive const void *. qsort and bsearch are the standard examples.
Q8. How can pointer to pointer simplify linked list deletion?Intermediate+
Keep a node_t **pp that points to the link (the head variable or a next field) leading to the current node. To delete, assign *pp = (*pp)->next. The head is just another link, so no special case and no previous-node pointer is needed. Without the trick you need a prev pointer and a separate branch for the head.
Q9. Why is converting char ** to const char ** unsafe?Advanced+
Through the const char ** a function could store the address of a const string into a char * variable of the caller; the caller could then modify read-only data without any cast. The rule that adds const at the first level does not extend to deeper levels. The safe form is char ** to const char *const *, and GCC reports the unsafe conversion as incompatible pointer types.
Q10. What are the problems of malloc in firmware and what are the alternatives?Advanced+
Problems: fragmentation after many allocations of different sizes, non-deterministic run time, out-of-memory handling at every call, heap and stack colliding in a small SRAM, and thread safety in an RTOS. Standards such as MISRA C ban dynamic allocation after initialisation. Alternatives: static buffers, fixed-size block pools with a free list (constant time), ring buffers, RTOS memory pools, and allocation only during start-up.
Q11. How do you design a safe release function for pool blocks?Advanced+
Take T **pp so the function can clear the caller’s pointer. Validate: pointer not NULL, inside the pool array, aligned to a block boundary, not already free (flag in the block header or a search of the free list). Return an error code instead of corrupting the list. Optionally fill the block with a pattern in debug builds to expose use-after-free.
Q12. What does const void * versus void * tell the caller of a function?Advanced+
const void *src promises that the function only reads the memory (like the source of memcpy); void *dst says it may write. It lets callers pass pointers to const objects (for example data in Flash) and gives the compiler a chance to flag accidental writes. Casting const away to call a function that writes is undefined behavior if the object really is const.
Study Plan: Using Your Score on These Pointer to Pointer Interview Questions
Score
Meaning
Next step
90–100%
Excellent
Continue to Lesson 9.4: pointers and strings.
70–89%
Good
Redo Examples 1, 3 and 7 of the examples page.
Below 70%
Revise
Re-read theory sections 1, 2, 4 and 7, then retake the quiz.
Habit to build: Whenever a function must hand back a pointer or move one, draw the caller’s pointer variable as a box and pass the box’s address.
Lesson 9.3 complete!
Next up: pointers and strings: literals, buffers, library functions and safe handling.
2 Comments