The sizeof operator gives yiou the soze of the variable
.
Therefore:
- int arr[20];
-
sizeof(arr);
-
will have a sizeof 80 since the array is local (on the stack). The 80 is 20 x 4 assuming int is 4 bytes.
However:
- void function(int arr[20])
-
{
-
sizeof(arr);
-
}
will show arr with a sizeof 4.
This is because the name of an array is the address of element 0. In the function, the argument is the address of an array of 20 int. It is the sizeof the address you see. Addresses are 4 bytes in 32-bit operating systems.
I suggest you go to the C/C++ Insights forum and read the article Arrays Revealed where all this is explained.