I understand that when we pass a pointer to a function by-value, the pointer gets copied and the function only operates with a copy which stores the address that is the same as the original’s, so it can be used to alter the value at the original address.
Now, if we pass an array to a function by-value, people say that this is the same as with the pointer. They also say that I can treat the array as-if it is a pointer.
But, to me, it looks much different! Because we pass an array by-value, the function will again make a copy. I am guessing that it copies the first array element. And this element does not store any address! So we lose the connection. What gets copied here?
>Solution :
You can’t pass an array by value, only by pointer or reference. If you try to pass it by value, the array will decay into a pointer to the 1st element, and the pointer will be passed by value.
What is array to pointer decay?