Pass Array To Function
When passing array to function in c
, it's actually just the pointer of the first element not the array copied to memory.
For example:
unsigned long getLength(int array[]) {
return sizeof(array);
}
Will be the same as
unsigned long getLength(int *array) {
return sizeof(array);
}
Since [[How variable work in C#Size of variable|size of pointer is 8
]], this is actually producing a wrong result. And return 8
for array of any size.
When passing array to a function, it only pass the first element reference pointer.