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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Do not use sizeof for array parameters
- Difference between pointer to an array and array of pointers
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- Program to reverse an array using pointers
- C program to sort an array using pointers
- Declare a C/C++ function returning pointer to array of integer pointers
- What is evaluation order of function parameters in C?
- Features and Use of Pointers in C/C++
- Applications of Pointers in C/C++
- How many levels of pointers can we have in C/C++
- Pointers in C/C++ with Examples
- What are near, far and huge pointers?
- Pointers vs References in C++
- Output of C programs | Set 64 (Pointers)
- Chain of Pointers in C with Examples
- Why do we need reference variables if we have pointers
- The length of a string using pointers
- What are Wild Pointers? How can we avoid?
- Check if a string is palindrome in C using pointers
- Difference between Iterators and Pointers in C/C++ with Examples