C Pointers and Arrays

C Pointers and Arrays (Beginner → Advanced)
Pointers and arrays are closely related in C.
Understanding this relationship is mandatory for DSA, memory concepts, embedded systems, and interviews.
Relationship Between Pointers and Arrays
->Array name itself is a pointer to the first element of the array.
arr→ address ofarr[0]&arr[0]→ same address
Array Access Using Pointer Arithmetic
- Pointer automatically moves by
sizeof(int)
Difference: arr vs &arr
| Expression | Meaning |
|---|---|
arr | Address of first element |
&arr | Address of entire array |
arr + 1 | Next element |
&arr + 1 | Next array block |
- Interview-tricky concept
Pointer vs Array (Important )
| Feature | Array | Pointer |
|---|---|---|
| Memory allocation | Fixed | Dynamic possible |
| Size | Fixed | Same as address |
| Can change address | No | Yes |
| Arithmetic | Limited | Full |
Arrays Passed to Functions (Always by Reference)
- No array copy is made
- Fast and memory efficient
Pointer to Array vs Array of Pointers
Pointer to Array
Array of Pointers
- Very common interview confusion
Pointers with Multidimensional Arrays
- Pointer must know column size
Array of Pointers (Strings Example)
- Used in command-line arguments
Pointer Arithmetic Rules
- Pointer + pointer (invalid)
Common Mistakes
- Confusing array with pointer
- Using
sizeof(pointer)instead ofsizeof(array) Wrong pointer type for 2D arrays- Accessing out-of-bounds memory
Interview Questions (Must Prepare)
Relationship between pointer and array
Difference between array and pointer
What is
arrvs&arr?How arrays are passed to functions?
Pointer to array vs array of pointers
2D array pointer declaration
Real-Life Use Cases
Dynamic memory management
String handling
Data structures
Embedded buffers
Command-line arguments
Summary
- Array name acts as pointer
- Pointer arithmetic enables fast access
- Arrays passed by reference
- 2D arrays require correct pointer type
- Extremely important for DSA & interviews
