In C, array parameters are treated as pointers. The following two definitions of foo() look different, but to the compiler they mean exactly the same thing. It’s preferable to use whichever syntax is more accurate for readability. If the pointer coming in really is the base address of a whole array, then we should use [ ].
Array parameters treated as pointers because of efficiency. It is inefficient to copy the array data in terms of both memory and time; and most of the times, when we pass an array our intention is to just tell the array we interested in, not to create a copy of the array.
Asked by Shobhit
- Double Pointer (Pointer to Pointer) in C
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- Dangling, Void , Null and Wild Pointers
- How to print size of array parameter in C++?
- What’s difference between “array” and “&array” for “int array” ?
- Function Pointer in C
- How to pass a 2D array as a parameter in C?
- Difference between pointer and array in C?
- Initialization of variables sized arrays in C
- Do not use sizeof for array parameters
- An Uncommon representation of array elements
- Pointer vs Array in C
- What all is inherited from parent class in C++?
- How to declare a pointer to a function?
- Output of the program | Dereference, Reference, Dereference, Reference....