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

C में Pointer Arithmetic: p+1, p-1 और Pointer Subtraction

p+1 एक byte नहीं जोड़ता — sizeof(type) bytes जोड़ता है. Array examples के साथ pointers का increment, decrement, subtraction और comparison master करें.

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

Pointer arithmetic में p+1 का क्या मतलब है?

p+1 pointed type के अगले element का address देता है: यह sizeof(type) bytes जोड़ता है, इसलिए int* चार bytes और double* आठ bytes आगे जाता है.

दो pointers घटाने पर क्या मिलता है?

q - p दोनों pointers के बीच elements की संख्या देता है (byte difference को sizeof type से divide करके), जो सिर्फ same array में valid है.

Pointers पर कौन-सी arithmetic operations illegal हैं?

दो pointers जोड़ना, pointers की multiplication या division — सब illegal हैं; सिर्फ integer जोड़ना/घटाना, pointer subtraction और comparison meaningful हैं.