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

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.3 · PRACTICE

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.

Section 1: Multiple Choice Questions — Double Pointers, void * and NULL

These pointer to pointer interview questions appear in nearly every embedded C screening round. Click an answer; explanations always appear.

1. What does int **pp hold?

2. If int v; int *p = &v; int **pp = &p;, what is **pp?

3. A function must change the caller’s char *s (make it point elsewhere). The parameter should be:

4. What is the type of argv in main(int argc, char *argv[]) after adjustment?

5. Which declaration is an array of 4 pointers to char?

6. Which statement about void * is true?

7. In C, converting a void * to int * requires:

8. Arithmetic on a void * is:

9. Which header defines NULL?

10. A pointer that still holds the address of freed memory is called:

11. A pointer that was never initialised is called:

12. Why do many embedded projects avoid malloc?

13. For qsort on an array of const char *, the comparator receives:

14. What does *pp = NULL; do inside safe_free(void **pp)?

15. Which is safest for a read-only buffer parameter of unknown type?

Section 2: Write or Evaluate (Fill in the Blanks)

Type the declaration or call for the first three items (spacing is flexible) and a short value for the rest.

1. Declare pp as a pointer to a pointer to uint8_t:

2. Write the prototype of get_buf returning int and delivering a char * through its only parameter:

3. Write the call that passes the address of the pointer cursor to advance:

4. int v = 5; int *p = &v; int **pp = &p; **pp = 9;. The value of v is

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

6. In const char *names[3] the number of pointers stored is

7. A pointer set to this value after free cannot dangle:

8. The generic object pointer type is *

Section 3: Which Concept Fits?

Choose the concept or syntax for each need, as asked in pointer to pointer interview questions about design.

NeedYour answerResult
Change the caller’s pointerT ** parameterarray of char pointersvoid * with sizeuint8_t *NULLdangling pointerstatic poolvoid *ctx
Table of strings with different lengthsT ** parameterarray of char pointersvoid * with sizeuint8_t *NULLdangling pointerstatic poolvoid *ctx
Generic copy of any objectT ** parameterarray of char pointersvoid * with sizeuint8_t *NULLdangling pointerstatic poolvoid *ctx
Byte arithmetic on a generic bufferT ** parameterarray of char pointersvoid * with sizeuint8_t *NULLdangling pointerstatic poolvoid *ctx
Mark a pointer as pointing to nothingT ** parameterarray of char pointersvoid * with sizeuint8_t *NULLdangling pointerstatic poolvoid *ctx
Pointer to freed memoryT ** parameterarray of char pointersvoid * with sizeuint8_t *NULLdangling pointerstatic poolvoid *ctx
Avoid heap fragmentationT ** parameterarray of char pointersvoid * with sizeuint8_t *NULLdangling pointerstatic poolvoid *ctx
Pass an opaque callback argumentT ** parameterarray of char pointersvoid * with sizeuint8_t *NULLdangling pointerstatic poolvoid *ctx

Section 4: True or False

Statements typical of pointer to pointer interview questions.

1. A function that receives int *p can change the caller’s pointer.

2. *pp is the pointer that pp points to.

3. A void * can be dereferenced directly.

4. NULL can be passed safely to strlen.

5. Setting a pointer to NULL after free prevents use-after-free of that pointer.

6. An array of pointers to strings stores the characters in the array.

7. Two different pointers can hold the address of the same object.

8. A static pool allocation takes unpredictable time.

Section 5: Code Snippet Challenges

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

Challenge 1 — Output?: Re-pointing through a double pointer
#include <stdio.h> static void f(int **pp, int *target) { *pp = target; } int main(void) { int a = 1, b = 2; int *p = &a; f(&p, &b); *p = 7; printf(“%d %d\n”, a, b); return 0; }

What is printed?

Output:
1 7
f makes p point to b; *p = 7 then changes b. a stays 1.
Challenge 2 — Output?: Walking an array of strings
#include <stdio.h> int main(void) { const char *w[] = {“one”, “two”, “three”}; const char **p = w; p++; printf(“%s %c %s\n”, *p, **p, p[1]); return 0; }

What is printed?

Output:
two t three
After p++, *p is “two”, **p is its first character t, and p[1] is “three”.
Challenge 3 — Output?: Swapping pointers, not strings
#include <stdio.h> #include <string.h> static void swap_ptr(const char **a, const char **b) { const char *t = *a; *a = *b; *b = t; } int main(void) { const char *x = “abc”, *y = “xyz”; swap_ptr(&x, &y); printf(“%s %s\n”, x, y); return 0; }

What is printed?

Output:
xyz abc
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)); return 0; }

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

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> static void reset(int *p) { p = NULL; } int main(void) { int v = 5; int *p = &v; reset(p); printf(“%s\n”, p ? “still set” : “NULL”); return 0; }

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> static void bad(int *p, int *t) { p = t; } static void 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); return 0; }
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+
AllowedNot allowed (standard C)
Hold the address of any objectDereference it
Convert to/from any object pointer without a cast (C)Pointer arithmetic
Pass to memcpy, qsort, callbacksHold 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+
arr_iq.c
#include <stdio.h> int main(void) { const char *a[] = {“on”, “off”, “toggle”}; char b[3][7] = {“on”, “off”, “toggle”}; printf(“%zu %zu\n”, sizeof b, sizeof a / sizeof a[0]); return 0; }
Output (verified by compiling and running)
21 3

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

ScoreMeaningNext step
90–100%ExcellentContinue to Lesson 9.4: pointers and strings.
70–89%GoodRedo Examples 1, 3 and 7 of the examples page.
Below 70%ReviseRe-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.

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 *