Ask sizeof about a pointer and it tells you about the pointer — not the pointee, not the value, not the array it might point into. Simple rule, three tempting wrong answers. This question from our C Programming Quiz App also carries an honest asterisk: the right answer is 8 on the platforms that matter today, and knowing why that qualifier exists is part of the lesson.
The Quiz Question
int x = 5;
int *p = &x;
printf("%d", sizeof(p));
What is printed by this code?
- 4
- 8
- 5
- Depends on the value of x
The Correct Answer: 8 (on 64-bit Systems)
sizeof(p) measures the pointer object itself — the variable that holds an address. On every mainstream 64-bit platform (x86-64 Linux/Windows/macOS, ARM64), addresses are 64 bits, so any object pointer is 8 bytes. Verified on gcc 13.3 (Linux x86-64) and Apple clang 21 (ARM64):
$ gcc -ansi -Wall -Wextra ptr.c && ./a.out sizeof(p) = 8 sizeof(*p) = 4 sizeof(x) = 4
The three lines are the whole question in miniature: the pointer is 8, the thing it points to is 4, and neither has anything to do with the value 5.
Why Each Wrong Answer Is Wrong
Why not 4?
Two ways to arrive at 4, one wrong and one outdated. The wrong way: 4 is sizeof(*p) — the pointed-to int — chosen by readers who mentally dereference. The outdated way: on 32-bit systems pointers really are 4 bytes, and a decade ago this quiz would have said so. That’s the platform note: the standard doesn’t fix pointer size at all; the quiz (like this site’s test rig) assumes the 64-bit systems that dominate today. On Arduino-class 8-bit AVR, pointers are 2 bytes.
Why not 5?
5 is the value of x — and sizeof never looks at values. It’s a compile-time operator that answers from the type alone. Which also answers option D:
Why not “Depends on the value of x”?
sizeof(p) would be 8 if x were 0, 2³¹−1, or anything else — and even if p were NULL or dangling. No expression is evaluated; the operand of sizeof (except for variable-length arrays) isn’t even executed. sizeof(p++) famously doesn’t increment p.
All Pointers, One Size — Almost
On a given mainstream platform, every object pointer has the same size: int *, char *, struct anything *, void * — all 8 bytes on 64-bit. The type changes what arithmetic and dereference mean, not how big the address is. This is why the earlier sizeof string questions keep landing on 8 the moment a pointer sneaks in where an array was expected — the single most common sizeof bug in real code:
void f(int arr[]) /* looks like an array... */
{
sizeof(arr); /* ...but this is 8, not the array */
}
A parameter declared as an array is a pointer, so inside any function, sizeof can never recover a passed array’s length. And the quiz code itself hides one more lesson: sizeof yields size_t, so printf("%d", sizeof(p)) is a format mismatch both compilers warn about — the clean spellings are %zu or an explicit cast, the same gotcha dissected in the sizeof vs strlen question.
Frequently Asked Questions
What is the size of a pointer in C?
Whatever the platform’s address width is: 8 bytes on 64-bit systems, 4 on 32-bit, 2 on small embedded targets. The C standard sets no fixed size — but all object pointers on a given mainstream platform share one.
Does sizeof(p) depend on what p points to?
No. It measures the pointer variable itself, from its type alone, at compile time. sizeof(*p) is how you ask about the pointed-to type — 4 for an int here.
Why does sizeof an array parameter give 8 inside a function?
Because array parameters are really pointers — the array decays at the call. sizeof sees a pointer type and reports pointer size, which is why lengths must be passed as separate parameters.
Related Reading
- sizeof of a String Array in C – Why “hi” Takes 3 Bytes
- sizeof vs strlen in C – What the Difference Tells You
- Void Pointer in C – The Round-Trip Cast
- Pointers in C – Complete Guide
Recommended Books
- The C Programming Language – Kernighan & Ritchie (India) | Amazon.com
- C Programming: A Modern Approach – K.N. King (India) | Amazon.com
This question is #133 in the C Programming Quiz App — 155 questions with explanations covering pointers, memory, operators, and more.
Download on Google Play →