0
PrintArray function
I have a problem determining how many elements in the array inside the function it works well outside the function why is that?? https://code.sololearn.com/cntt8cGTdFfk/?ref=app
2 odpowiedzi
+ 4
When an array is passed to a function, it decays to a pointer and hence loses the size property. The sizeof() function will only show the size of the pointer and not the size of the entire array.
The way around this is to provide the size information to the function as a parameter, before the decaying happens.
void printArray(int* arr, int size);
which can then be called in main as
printArray(arr, sizeof(arr)/sizeof(int));
0
I thought so.. thanks everyone 😃