Quiz-Pointer Arithmetic 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.2 · PRACTICE

Pointer Arithmetic Interview Questions for Embedded C: Quiz and Code Challenges

57 questions: multiple choice, write-the-expression blanks, an expression-matching table, true/false, 6 code challenges with real output and 12 detailed interview answers. Treat it as a model for pointer arithmetic 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 — Pointer Arithmetic

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

1. If uint32_t *p holds 0x20000000, what does p + 2 hold?

2. For int a[10], a[3] is equivalent to:

3. What is the type of the result of subtracting two int * pointers into one array?

4. Which pointer operation is NOT allowed?

5. What does *p++ do?

6. What does (*p)++ do?

7. sizeof(a) for int a[5] on the Cortex-M4 is:

8. Inside a function with parameter int a[5], sizeof(a) is:

9. Which pointer value is valid to form but not to dereference?

10. After int m[3][4], the expression m + 1 advances by:

11. How is a pointer to a row of 4 ints declared?

12. Which statement about an array name is true?

13. Reading a[n] for int a[n] is:

14. What is (uint8_t *)p + 1 if p is a uint32_t * at 0x100?

15. Which type should hold an element count?

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

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

1. Write the expression for the address of element 5 of array buf (use the address-of operator):

2. Write the expression equal to a[i] using a dereference and addition:

3. Write the number of elements of array t using sizeof:

4. uint16_t *p at 0x2000 0100. p + 3 is 0x

5. int a[] = {5,6,7,8}; int *p = a + 1; *p++;. Now *p is

6. For int a[8], &a[6] - &a[2] equals

7. A ring buffer of size 8: the next index after 7 is

8. int m[3][4] occupies bytes on the Cortex-M4

Section 3: Which Expression Fits?

Choose the expression for each task, as asked in pointer arithmetic interview questions about syntax.

TaskYour answerResult
Next element after pp + 1q – p*p++(*p)++int (*p)[4]int *p[4](uint8_t *)wa + n
Number of elements between p and qp + 1q – p*p++(*p)++int (*p)[4]int *p[4](uint8_t *)wa + n
Read then advancep + 1q – p*p++(*p)++int (*p)[4]int *p[4](uint8_t *)wa + n
Increment the pointed-to objectp + 1q – p*p++(*p)++int (*p)[4]int *p[4](uint8_t *)wa + n
Pointer to a row of 4 intsp + 1q – p*p++(*p)++int (*p)[4]int *p[4](uint8_t *)wa + n
Array of 4 int pointersp + 1q – p*p++(*p)++int (*p)[4]int *p[4](uint8_t *)wa + n
Byte step through a word arrayp + 1q – p*p++(*p)++int (*p)[4]int *p[4](uint8_t *)wa + n
Pointer one past the endp + 1q – p*p++(*p)++int (*p)[4]int *p[4](uint8_t *)wa + n

Section 4: True or False

Statements typical of pointer arithmetic interview questions.

1. Adding 1 to an int * adds one byte to the address.

2. a[i] and i[a] are equivalent.

3. An array name can be assigned a new address.

4. Pointer subtraction between unrelated arrays is well defined.

5. A pointer one past the end of an array can be compared with other pointers into the array.

6. p + q for two pointers is a compile error.

7. *p++ increments the value p points to.

8. A function parameter declared as int a[10] gets a copy of 10 ints.

Section 5: Code Snippet Challenges

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

Challenge 1 — Output?: Positive and negative offsets
#include <stdio.h> int main(void) { int a[] = {10, 20, 30, 40, 50}; int *p = a + 1; printf(“%d %d %d\n”, *p, *(p + 2), p[-1]); return 0; }

What is printed?

Output:
20 40 10
p points to a[1] = 20; p + 2 is a[3] = 40; p[-1] is a[0] = 10.
Challenge 2 — Output?: Postfix versus parentheses
#include <stdio.h> int main(void) { int a[] = {1, 2, 3, 4}; int *p = a; int x = *p++; int y = *p; (*p)++; printf(“%d %d %d\n”, x, y, a[1]); return 0; }

What is printed?

Output:
1 2 3
*p++ reads a[0] = 1 and moves p to a[1]; y reads 2; (*p)++ then makes a[1] = 3.
Challenge 3 — Output?: Different pointer types
#include <stdio.h> #include <stdint.h> int main(void) { uint16_t h[4] = {0x0102, 0x0304, 0x0506, 0x0708}; uint16_t *p = h; uint8_t *b = (uint8_t *)h; printf(“%04X %02X %td\n”, *(p + 2), b[3], (char *)(p + 3) – (char *)p); return 0; }

What is printed on a little-endian machine?

Output:
0506 03 6
*(p + 2) is h[2] = 0506; b[3] is the high byte of h[1] = 0x0304, which is 03; three uint16_t elements are 6 bytes.
Challenge 4 — Output?: Row pointers
#include <stdio.h> int main(void) { int m[2][3] = {{1, 2, 3}, {4, 5, 6}}; int (*r)[3] = m + 1; printf(“%d %d %d\n”, (*r)[0], r[0][2], *(*m + 4)); return 0; }

What is printed?

Output:
4 6 5
r points to row 1 (4, 5, 6): (*r)[0] = 4 and r[0][2] = 6. *m is row 0 as an int pointer, so *(*m + 4) is the fifth element, 5.
Challenge 5 — Find the bug: The loop condition
#include <stdio.h> int main(void) { int a[4] = {1, 2, 3, 4}; int s = 0; for (int i = 0; i <= 4; i++) s += a[i]; printf(“%d\n”, s); return 0; }

What does GCC report with -O2 -Wall?

Compiler result:offbyone.c: In function ‘main’: offbyone.c:7:15: warning: iteration 4 invokes undefined behavior [-Waggressive-loop-optimizations] 7 | s += a[i]; | ~^~~ offbyone.c:6:23: note: within this loop 6 | for (int i = 0; i <= 4; i++) | ~~^~~~The loop runs for i = 0 to 4, but valid indices are 0 to 3. Use i < 4.
Challenge 6 — Find the bug: Adding two pointers
#include <stdio.h> int main(void) { int a[3] = {1, 2, 3}; int *p = a, *q = a + 2; printf(“%d\n”, *(p + q)); return 0; }

What does GCC report?

Compiler result:addptr.c: In function ‘main’: addptr.c:6:24: error: invalid operands to binary + (have ‘int *’ and ‘int *’) 6 | printf(“%d\n”, *(p + q)); | ^Adding two pointers is meaningless. Use p + (q - p) or just q.

Section 6: Pointer Arithmetic Interview Questions for Embedded C (with Detailed Answers)

Pointer arithmetic interview questions test scaling, the array and pointer relationship, increment idioms, pointer subtraction and bounds. Click a question for a model answer.

Q1. What is pointer arithmetic?Basic+

The set of valid operations on pointers: adding or subtracting an integer, subtracting two pointers into the same array and comparing pointers. Adding n advances n elements of the pointed-to type, so the compiler multiplies by sizeof(*p). The result must stay inside the array or one past its end.

Q2. Why is a[i] equal to *(a + i)?Basic+
subscript_iq.c
#include <stdio.h> int main(void) { int a[3] = {7, 8, 9}; printf(“%d %d %d\n”, a[1], *(a + 1), 1[a]); return 0; }
Output (verified by compiling and running)
8 8 8

The language defines the subscript that way. An array name decays to a pointer to its first element, a + i moves i elements and the star reads the element. Because addition is commutative, i[a] works too, but is never used.

Q3. What is the difference between an array and a pointer?Basic+
ArrayPointer
StorageHolds the elementsHolds one address
sizeofWhole arrayPointer size
AssignableNoYes
IncrementNoYes
As a parameterBecomes a pointerIs a pointer
Address-of&a has type pointer-to-array&p is pointer-to-pointer

An array name converts to a pointer to its first element in most expressions, which makes the two look alike.

Q4. Explain *p++, (*p)++, *++p and ++*p.Intermediate+
ExpressionEffect
*p++value is the old *p; p advances
(*p)++value is the old *p; the object increases by 1
*++pp advances; value is the new *p
++*pthe object increases by 1; value is the new value

Postfix operators bind tighter than prefix operators, and prefix operators associate right to left.

Q5. What does sizeof return for an array parameter and why?Intermediate+

The size of a pointer. A parameter declared int a[10] is adjusted to int *a, so the function has no knowledge of the original length. Pass the length separately. Inside the caller, where the real array is visible, sizeof a / sizeof a[0] gives the element count.

Q6. What is the one-past-the-end pointer and why does C allow it?Intermediate+

For an array of n elements, a + n may be formed and compared but not dereferenced. It allows the idiomatic loop for (p = a; p != a + n; p++) and the length expression end - begin. Pointers further out, or before the first element, are undefined even if never used, because on some architectures the computation itself can trap or wrap.

Q7. How does a ring buffer use pointer arithmetic?Intermediate+
ring_iq.c
#include <stdio.h> #include <stdint.h> int main(void) { uint8_t buf[4]; uint8_t *head = buf; for (int i = 0; i < 6; i++) { *head++ = (uint8_t)i; if (head == buf + 4) head = buf; } printf(“head index %td, buf: %u %u %u %u\n”, head – buf, buf[0], buf[1], buf[2], buf[3]); return 0; }
Output (verified by compiling and running)
head index 2, buf: 4 5 2 3

Producer and consumer pointers advance with *p++ and wrap by comparing against buf + size; a counter (or one wasted slot) distinguishes full from empty. For power-of-two sizes, indices with a mask (i & (N-1)) are an alternative.

Q8. How do you step through a structure or buffer byte by byte?Intermediate+

Cast the address to const uint8_t * (or unsigned char *): ISO C allows any object to be examined through a character type. Then loop for (i = 0; i < sizeof obj; i++). This is used for checksums, serialisation and hex dumps; it exposes padding bytes and the byte order, so do not use it to define a wire format.

Q9. Why can (uint32_t *)buf cause problems when buf is a byte array?Advanced+

The Cortex-M4 can do unaligned word loads for normal LDR/STR, but not for LDM, LDRD or exclusive accesses, and the compiler may assume the alignment of the pointed-to type, generating instructions that fault when the address is odd. In addition, strict aliasing says that reading a uint8_t array through a uint32_t pointer is undefined. Use memcpy into a local variable, or build the value with shifts (Lesson 9.5).

Q10. What is the difference between int *p[4] and int (*p)[4]?Advanced+

The first is an array of 4 pointers to int (each can point to a different buffer). The second is a single pointer to an array of 4 ints (used for row pointers of a matrix). Reading right to left: p[4] binds first, so it is an array of pointers; the parentheses force the star first, so it is a pointer to an array.

Q11. How can pointer arithmetic go wrong with signed and unsigned types?Advanced+

Mixing size_t (unsigned) and int in an expression converts the int to unsigned: p + n - 1 with n = 0 and unsigned n underflows to a huge number, and i >= 0 is always true for an unsigned counter, giving an endless loop when counting down. Use ptrdiff_t for differences and signed counters for downward loops, or the idiom while (i--).

Q12. How would you find the length of a zero-terminated string without strlen?Advanced+
strlen_iq.c
#include <stdio.h> #include <stddef.h> static size_t len(const char *s) { const char *p = s; while (*p) p++; return (size_t)(p – s); } int main(void) { printf(“%zu %zu\n”, len(“Cortex”), len(“”)); return 0; }
Output (verified by compiling and running)
6 0

Walk a copy of the pointer to the terminator and subtract the start. The result is the number of characters excluding the zero. The loop reads one byte per iteration; an optimised library version reads words, which requires care about alignment and reading past the end.

Study Plan: Using Your Score on These Pointer Arithmetic Interview Questions

ScoreMeaningNext step
90–100%ExcellentContinue to Lesson 9.3: pointer to pointer, void pointers and NULL.
70–89%GoodRedo Examples 1, 4 and 6 of the examples page.
Below 70%ReviseRe-read theory sections 1, 2, 3 and 6, then retake the quiz.
Habit to build: Write the byte offset next to every pointer expression you read: element index times sizeof the type.

Need Help or More Information?

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

1 Comment

Leave a Reply

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