c++ - What is array decaying? -


what decaying of array? there relation array pointers?

it's said arrays "decay" pointers. c++ array declared int numbers [5] cannot re-pointed, i.e. can't numbers = 0x5a5aff23. more importantly term decay signifies loss of type , dimension; numbers decay int* losing dimension information (count 5) , type not int [5] more. here cases decay doesn't happen.

if you're passing array value, you're doing copying pointer - pointer array's first element copied parameter (whose type should pointer array element's type). works due array's decaying nature; once decayed, sizeof no longer gives complete array's size, because becomes pointer. why it's preferred (among other reasons) pass reference or pointer.

three ways pass in array1:

void by_value(const t* array)   // const t array[] means same void by_pointer(const t (*array)[u]) void by_reference(const t (&array)[u]) 

the last 2 give proper sizeof info, while first 1 won't since array argument has decayed assigned parameter.

1 constant u should known @ compile-time.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -