Need Help or More Information?
Questions about this free C programming course, embedded C training or career guidance? Get in touch.
Pointers Quiz and Interview Questions
Test your knowledge of dereferencing, pointer types and pointer arithmetic with MCQs, output prediction, coding practice and embedded C interview questions.
What You Will Learn
This final lecture of the block is a practice lab for our free C programming course. Use this free C tutorial page to check that you really understood dereferencing, pointer sizes and pointer arithmetic, and to prepare answers for embedded C programming interviews. Try every question before opening the answer.
- Ten multiple choice questions with answers
- Output prediction exercises you can verify by compiling
- Coding challenges for practice
- Interview questions with short model answers
Prerequisites
Finish lectures 6 to 9 of this free embedded C course: dereferencing, pointer types and sizes, pointer arithmetic and safe pointer movement.
Quick Recap Table
| Concept | One-line rule |
|---|---|
| Dereference | *p is the object stored at the address in p |
| *(&x) | Equals x |
| sizeof(p) | Same for all object pointers on a machine |
| sizeof(*p) | Follows the base type |
| p + n | Moves n elements, n * sizeof(*p) bytes |
| q – p | Element count, type ptrdiff_t |
Multiple Choice Questions
- What does the expression
*psmean when ps is an int pointer?- A. The address of ps
- B. The int stored at the address held in ps
- C. ps multiplied by something
- D. The size of ps
Show answer
B. The star dereferences the pointer.
- If x is an int, what is
*(&x)equal to?- A. The address of x
- B. Zero
- C. x
- D. A compile error
Show answer
C. The two operators cancel.
- On a 32-bit ARM Cortex-M, what is sizeof(double *)?
- A. 2
- B. 4
- C. 8
- D. 16
Show answer
B. Pointers are 32 bits wide there. The pointed-to double is 8 bytes, but the pointer is 4.
- Why must a pointer have a base type?
- A. To make it larger
- B. To tell the compiler how many bytes to access and how to interpret them
- C. Because C forbids untyped data
- D. To store the variable name
Show answer
B.
- An int pointer p holds address 2000 and an int is 4 bytes. What address is in p + 3?
- A. 2003
- B. 2006
- C. 2012
- D. 2024
Show answer
C. 2000 + 3 * 4 = 2012.
- Which pointer operation is NOT allowed?
- A. p + 1
- B. p – 1
- C. q – p (same array)
- D. p + q
Show answer
D. Adding two pointers is meaningless.
- What does
(*p)++do?- A. Moves p to the next element
- B. Increments the value p points to
- C. Increments the address of p
- D. Nothing
Show answer
B.
- What is the type of the result of subtracting two int pointers?
- A. int *
- B. unsigned char
- C. ptrdiff_t
- D. float
Show answer
C. It is a signed integer type declared in stddef.h.
- Which is the correct format specifier to print a pointer?
- A. %d
- B. %u
- C. %p with a (void *) cast
- D. %s
Show answer
C.
- Which pointer position is legal to form but illegal to dereference?
- A. The first element
- B. The middle element
- C. One past the last element
- D. Three past the last element
Show answer
C.
Output Prediction Exercises
Predict the output of each snippet on a machine with 4-byte int, then compile and check yourself.
Exercise 1
int a[] = {2, 4, 6, 8};
int *p = a;
p++;
printf("%d %d\n", *p, *(p + 2));
Show answer
Output: 4 8. After p++ the pointer is on element 1 (value 4), and p + 2 is element 3 (value 8).
Exercise 2
int a[] = {2, 4, 6, 8};
int *p = a;
(*p)++;
printf("%d %d\n", a[0], *p);
Show answer
Output: 3 3. The parentheses make the increment apply to the value, which is also a[0].
Exercise 3
double d[3] = {1.0, 2.0, 3.0};
double *p = &d[0];
double *q = &d[2];
printf("%td %td\n", q - p, (char *)q - (char *)p);
Show answer
Output: 2 16. Two elements apart, each element 8 bytes.
Coding Challenges
- Write a function
void swap_int(int *a, int *b)that exchanges two integers through their addresses. - Write a function that returns the largest element of an int array using only a begin pointer and an end pointer.
- Write a function that reverses an array in place using two pointers that move towards each other.
- Print the four bytes of a uint32_t in memory order using an unsigned char pointer, and state whether your machine is little-endian.
Hint for challenge 3
Start one pointer at the first element and one at the last. Swap the values they point to, then move the first forward and the second backward until they meet.
Embedded C Interview Questions
1. What is a pointer and why is it useful in embedded systems?
A pointer is a variable that holds a memory address. Embedded code uses pointers to access memory-mapped registers, walk buffers, pass large data without copying and build driver callbacks.
2. What is the difference between a pointer and an array name?
An array name usually converts to a pointer to its first element in expressions, but an array is the storage itself, and sizeof(array) gives the whole array size while sizeof(pointer) gives the pointer size.
3. What does it mean to dereference a NULL pointer?
It is undefined behaviour. On many systems it crashes, and on some microcontrollers address zero is valid memory so it may silently read vector table data.
4. Why is pointer arithmetic scaled by the type size?
So that p + 1 always refers to the next element regardless of type, and the programmer does not have to write size multiplications.
5. What is the use of volatile with pointers to registers?
It tells the compiler that the value can change outside the program’s control, so every access must really be performed and not optimised away.
6. What is a void pointer, and what are its limits?
It is a generic address with no base type. You can assign any object pointer to it, but you must cast it back before dereferencing and you cannot do arithmetic on it in standard C.
7. Explain the difference between *p++ and (*p)++.
*p++ reads the value and then advances the pointer. (*p)++ increments the pointed-to value and leaves the pointer in place.
8. What is a dangling pointer?
A pointer to memory that is no longer valid, for example the address of a local variable after its function returned, or memory that has been freed.
9. What is endianness and how can you detect it with pointers?
It is the byte order of multi-byte values in memory. Store a known 32-bit value and read its first byte through an unsigned char pointer: the least significant byte first means little-endian.
10. Why can unaligned pointer access be a problem?
Some cores fault or run slowly when a multi-byte access does not start on a suitably aligned address. Copy with memcpy or access byte by byte when decoding raw packets.
Common Mistakes to Revise
- Using an uninitialised pointer.
- Confusing the size of a pointer with the size of its target.
- Expecting p + 4 to move four bytes for an int pointer.
- Stepping beyond one past the end of an array.
- Printing pointers with %d.
Key Takeaways
- Dereferencing lets you read and write the object at an address.
- The base type decides both access width and arithmetic step.
- Pointer arithmetic belongs inside arrays, with one-past-the-end as the limit.
- Practise with small programs and check your predictions by compiling.
Conclusion
You have covered the core of pointer usage in this free C programming course: what dereferencing does, how types control size, and how arithmetic moves across arrays. If you can answer the questions on this page without looking, you are ready for the next topic in embedded C programming. Keep practising, because comfort with pointers is what separates a beginner from a firmware engineer.
Frequently Asked Questions
Where can I learn embedded C programming for free?
This free embedded C course on EmbeddedPathashala covers it step by step, from basics to pointers and beyond.
How many hours should I spend on pointers?
Plan several short sessions, and write small programs each time rather than only reading.
Are pointer questions common in embedded interviews?
Yes, nearly every embedded C interview asks about pointers, volatile and memory layout.
What should I study after pointer arithmetic?
Arrays and pointers together, strings, pointers to pointers and function pointers.
Is this free C tutorial suitable for beginners?
Yes. Every lecture starts from the basics and includes runnable examples with output.
Keep Going With the Free C Course
Share your solutions to the coding challenges, revisit any lecture that felt shaky, and move on to the next chapter when you are ready.
Need Help or More Information?
Questions about this free C programming course, embedded C training or career guidance? Get in touch.

2 Comments