Pointers and Arrays
An array's name decays to a pointer to its first element — but arrays and pointers are not the same thing.
Intermediate
data[i] is exactly *(data + i). When passed to a function, an array becomes a pointer and loses its size:
void print_all(const int *arr, size_t n) { /* pass the length separately */ }
Differences: sizeof(array) gives the whole array's size, sizeof(pointer) gives the pointer's size; you can reassign a pointer but not an array name.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.