Does *p + 1 add 1 to the value, or move the pointer to the next element? It’s one or the other depending on where the parentheses fall — and there are none here, so operator precedence decides. This question from our C Programming Quiz App is the mirror image of the *(p + 1) question, and mixing the two up is one of the most common early pointer mistakes.
The Quiz Question
int x = 7;
int *p = &x;
printf("%d", *p + 1);
What is printed by this code?
- 7
- 8
- Address of x + 1
- Compile error
The Correct Answer: 8
Unary * binds tighter than binary +, so *p + 1 parses as (*p) + 1: dereference first (getting 7), then add 1 to the value. The pointer never moves. Verified on gcc 13.3 and Apple clang 21, clean under -Wall -Wextra:
$ gcc -Wall -Wextra prec.c && ./a.out 8
To see both readings side by side, we ran the array version where each expression is valid:
int arr[] = {7, 100};
int *p = arr;
printf("%d %d", *p + 1, *(p + 1));
8 100
*p + 1 is “the value, plus one” → 8. *(p + 1) is “the next element” → 100. Same three tokens, completely different results — the parentheses are everything.
Why Each Wrong Answer Is Wrong
Why not 7?
7 is just *p, ignoring the + 1. The addition is real — it simply happens after the dereference, on the plain int that *p produced.
Why not “Address of x + 1”?
That would be the result of p + 1 — pointer arithmetic on the address, with no dereference at all. Precedence rules mean the * consumes p before the + gets a say, so the addition operates on an int value, not on an address. (And in this single-variable program, dereferencing p + 1 would actually be undefined behavior — there’s no next element after a lone int.)
Why not “Compile error”?
Every step is well-typed: *p is an int, int + 1 is an int, and %d prints it. Both compilers are silent even with all warnings on.
The Precedence Rule Worth Memorizing
Unary operators (*, &, !, ++-prefix, --negation) bind tighter than every binary arithmetic operator. So:
*p + 1 ≡ (*p) + 1 value arithmetic *p - *q ≡ (*p) - (*q) difference of two values *p * 2 ≡ (*p) * 2 the first * is dereference, the second multiplies
The one family unary * does not outrank is the postfix operators — (), [], ++/-- after the operand — which is exactly why *p++ moves the pointer instead of incrementing the value. When in doubt, write the parentheses: the compiler doesn’t need them, but the next reader of your code does.
Frequently Asked Questions
Is *p + 1 the same as *(p + 1)?
No. *p + 1 is (*p) + 1 — dereference, then add 1 to the value. *(p + 1) advances the pointer one element first, then dereferences — reading the next element. With p pointing at 7 in {7, 100}, they yield 8 and 100 respectively.
Does *p + 1 modify x or move the pointer?
Neither. It computes a temporary value — x‘s 7 plus 1 — and hands it to printf. Both x and p are unchanged afterwards.
What precedence does the dereference operator have?
Unary * outranks all binary arithmetic and comparison operators, but ranks below postfix operators like [], (), and postfix ++. Hence *p + 1 dereferences first, while *p++ increments the pointer first.
Related Reading
- Pointers in C – Complete Guide
- Arithmetic Operators in C
- Array Summation Using Pointers
- C Aptitude Questions and Answers
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 #155 in the C Programming Quiz App — 155 questions with explanations covering operators, pointers, memory, and more.
Download on Google Play →