Difference Between Array and Pointer in C (With Table)
Arrays and pointers look similar but differ in sizeof, assignment, memory and behaviour. Full comparison table plus the famous sizeof proof program.
Why the confusion exists
arr becomes &arr[0], and arr[i] equals *(arr + i). But an array is not a pointer — and 4 differences prove it.Difference 1: sizeof (the famous proof)
#include <stdio.h>
int main() {
int arr[5] = {1, 2, 3, 4, 5};
int *p = arr;
printf("sizeof(arr) = %zu\n", sizeof(arr)); /* 20: whole array */
printf("sizeof(p) = %zu\n", sizeof(p)); /* 8: just a pointer */
return 0;
}
sizeof sees the truth: arr is a 20-byte block of 5 ints; p is an 8-byte address holder. If arrays were pointers, both would print 8.
Difference 2: Assignment
int arr[5], brr[5];
int *p, *q;
p = q; /* OK: pointers can be reassigned */
p = arr; /* OK: array decays to pointer */
arr = brr; /* ERROR: array name is not modifiable */
arr++; /* ERROR: cannot move an array */
A pointer is a variable — it can point anywhere, any time. An array name is a fixed label for a fixed block of memory; it can never be reassigned or incremented.
Difference 3: Memory
- Array: one allocation — the elements themselves. There is no separate "arr variable" storing an address.
- Pointer: its own memory (8 bytes) that stores an address, separate from whatever it points to.
Difference 4: Behaviour with strings
char arr[] = "hello"; /* modifiable copy in the array */
char *p = "hello"; /* points to read-only literal */
arr[0] = 'H'; /* OK */
p[0] = 'H'; /* CRASH: undefined behaviour */
Complete comparison table
| Point | Array | Pointer |
|---|---|---|
| sizeof | Total bytes of all elements | Size of an address (4/8 bytes) |
| Reassignment | Impossible | Any time |
| arr++ / p++ | Error | Valid |
| Memory | Block of elements only | Separate 8-byte address holder |
| &name | Address of whole array (int (*)[5]) | Address of the pointer variable |
| String literal init | Writable copy | Read-only reference |
Confusion क्यों होता है
arr बन जाता है &arr[0], और arr[i] = *(arr + i). लेकिन array pointer नहीं है — और 4 अंतर इसे prove करते हैं.अंतर 1: sizeof (famous proof)
#include <stdio.h>
int main() {
int arr[5] = {1, 2, 3, 4, 5};
int *p = arr;
printf("sizeof(arr) = %zu\n", sizeof(arr)); /* 20: पूरा array */
printf("sizeof(p) = %zu\n", sizeof(p)); /* 8: सिर्फ pointer */
return 0;
}
sizeof सच दिखाता है: arr पांच ints का 20-byte block है; p आठ-byte का address holder. अगर arrays pointers होते, तो दोनों 8 print करते.
अंतर 2: Assignment
int arr[5], brr[5];
int *p, *q;
p = q; /* OK: pointers reassign हो सकते हैं */
p = arr; /* OK: array pointer में decay होता है */
arr = brr; /* ERROR: array name modifiable नहीं है */
arr++; /* ERROR: array को move नहीं कर सकते */
Pointer एक variable है — कभी भी, कहीं भी point कर सकता है. Array name memory के fixed block का fixed label है; कभी reassign या increment नहीं हो सकता.
अंतर 3: Memory
- Array: एक allocation — खुद elements. कोई अलग "arr variable" नहीं जो address store करे.
- Pointer: अपनी memory (8 bytes) जो address store करती है, उससे अलग जिसे वह point करता है.
अंतर 4: Strings के साथ behaviour
char arr[] = "hello"; /* array में modifiable copy */
char *p = "hello"; /* read-only literal को point करता */
arr[0] = 'H'; /* OK */
p[0] = 'H'; /* CRASH: undefined behaviour */
पूरी comparison table
| Point | Array | Pointer |
|---|---|---|
| sizeof | सभी elements के total bytes | Address का size (4/8 bytes) |
| Reassignment | Impossible | कभी भी |
| arr++ / p++ | Error | Valid |
| Memory | सिर्फ elements का block | अलग 8-byte address holder |
| &name | पूरे array का address (int (*)[5]) | Pointer variable का address |
| String literal init | Writable copy | Read-only reference |
Frequently Asked Questions
Is an array name a pointer in C?
No. An array name decays to a pointer to its first element in most expressions, but sizeof, & and non-assignability prove it is a distinct array type.
Why does sizeof(arr) differ from sizeof(p)?
sizeof(arr) returns the total bytes of all elements (e.g. 20 for int[5]), while sizeof(p) returns only the size of an address (8 bytes on 64-bit).
Why does char *p = "hello"; p[0]='H'; crash?
The string literal lives in read-only memory; writing through the pointer is undefined behaviour. A char array initialized from the literal holds a writable copy instead.