Free tutorials in Hindi & English Daily computer, mobile and IT guides Beginner friendly learning
Blog · C Pointers · 03 Jul 2026 · Hindi + English

Pointer Arithmetic in C: p+1, p-1 and Pointer Subtraction

p+1 does not add 1 byte — it adds sizeof(type) bytes. Master increment, decrement, subtraction and comparison of pointers with array examples.

The golden rule of pointer arithmetic

p + 1 does NOT add 1 byte. It adds sizeof(pointed-type) bytes. For an int * (4-byte int), p + 1 jumps 4 bytes forward — to the next int, not the next byte.
int  *pi;   /* pi + 1  →  address + 4 (next int)    */
char *pc;   /* pc + 1  →  address + 1 (next char)   */
double *pd; /* pd + 1  →  address + 8 (next double) */

Proof program

#include <stdio.h>

int main() {
    int arr[3] = {10, 20, 30};
    int *p = arr;

    printf("p     = %p  value = %d\n", (void*)p,     *p);
    printf("p + 1 = %p  value = %d\n", (void*)(p+1), *(p+1));
    printf("p + 2 = %p  value = %d\n", (void*)(p+2), *(p+2));
    return 0;
}
p = 0x7ffe1000 value = 10 p + 1 = 0x7ffe1004 value = 20 p + 2 = 0x7ffe1008 value = 30

Addresses jump by 4 each time (int = 4 bytes), and each jump lands exactly on the next array element. This is why *(p + i) and arr[i] are the same thing.

Allowed operations

OperationExampleResult
Add integerp + 3Address of 3 elements ahead
Subtract integerp - 2Address of 2 elements back
Increment / decrementp++, p--Move one element
Pointer − pointerq - pNumber of elements between them
Comparisonp < qValid within the same array
Not allowed: adding two pointers (p + q), multiplying or dividing pointers. These have no meaning for addresses.

Pointer subtraction example

#include <stdio.h>

int main() {
    int arr[5] = {1, 2, 3, 4, 5};
    int *first = &arr[0];
    int *last  = &arr[4];

    printf("Elements between: %ld\n", last - first);   /* 4, not 16 */
    return 0;
}
Elements between: 4

last - first gives 4 elements, even though the byte difference is 16 — pointer subtraction automatically divides by sizeof(int).

Classic use: traversing an array with a pointer

#include <stdio.h>

int main() {
    int marks[5] = {78, 85, 92, 66, 74};
    int sum = 0;

    for (int *p = marks; p < marks + 5; p++)
        sum += *p;

    printf("Total = %d\n", sum);
    return 0;
}
Total = 395

Pointer arithmetic का golden rule

p + 1 एक byte नहीं जोड़ता. यह sizeof(pointed-type) bytes जोड़ता है. int * (4-byte int) के लिए p + 1 चार bytes आगे jump करता है — अगले int पर, अगले byte पर नहीं.
int  *pi;   /* pi + 1  →  address + 4 (अगला int)    */
char *pc;   /* pc + 1  →  address + 1 (अगला char)   */
double *pd; /* pd + 1  →  address + 8 (अगला double) */

Proof program

#include <stdio.h>

int main() {
    int arr[3] = {10, 20, 30};
    int *p = arr;

    printf("p     = %p  value = %d\n", (void*)p,     *p);
    printf("p + 1 = %p  value = %d\n", (void*)(p+1), *(p+1));
    printf("p + 2 = %p  value = %d\n", (void*)(p+2), *(p+2));
    return 0;
}
p = 0x7ffe1000 value = 10 p + 1 = 0x7ffe1004 value = 20 p + 2 = 0x7ffe1008 value = 30

Addresses हर बार 4 से बढ़ते हैं (int = 4 bytes), और हर jump exactly अगले array element पर पहुंचता है. इसीलिए *(p + i) और arr[i] एक ही चीज़ हैं.

Allowed operations

OperationExampleResult
Integer जोड़नाp + 33 elements आगे का address
Integer घटानाp - 22 elements पीछे का address
Increment / decrementp++, p--एक element move
Pointer − pointerq - pदोनों के बीच elements की संख्या
Comparisonp < qSame array के अंदर valid
Allowed नहीं: दो pointers जोड़ना (p + q), pointers की multiplication या division. Addresses के लिए इनका कोई मतलब नहीं.

Pointer subtraction example

#include <stdio.h>

int main() {
    int arr[5] = {1, 2, 3, 4, 5};
    int *first = &arr[0];
    int *last  = &arr[4];

    printf("Elements between: %ld\n", last - first);   /* 4, 16 नहीं */
    return 0;
}
Elements between: 4

last - first देता है 4 elements, जबकि byte difference 16 है — pointer subtraction अपने आप sizeof(int) से divide कर देता है.

Classic use: Pointer से array traverse करना

#include <stdio.h>

int main() {
    int marks[5] = {78, 85, 92, 66, 74};
    int sum = 0;

    for (int *p = marks; p < marks + 5; p++)
        sum += *p;

    printf("Total = %d\n", sum);
    return 0;
}
Total = 395

Frequently Asked Questions

What does p+1 mean in pointer arithmetic?

p+1 gives the address of the next element of the pointed type: it adds sizeof(type) bytes, so int* moves 4 bytes and double* moves 8.

What does subtracting two pointers give?

q - p gives the number of elements between the two pointers (byte difference divided by sizeof type), valid only within the same array.

Which arithmetic operations are illegal on pointers?

Adding two pointers, multiplying or dividing pointers are all illegal; only integer addition/subtraction, pointer subtraction and comparison are meaningful.