#include <stdio.h> int foo(int a[100]) { return sizeof(a); } int main() { int a[10]; printf("%d", foo(a)); }
What will be the output of the above code ignoring any compiler warnings and assuming sizeof(int) as 4 when run on a 64 bit machine?
Some good reference -
https://stackoverflow.com/questions/20721294/size-of-int-and-sizeof-int-pointer-on-a-64-bit-machine
https://www.geeksforgeeks.org/how-arrays-are-passed-to-functions-in-cc/
In C programming language, array parameters are treated as pointers .So here we are passing base address of array a through function foo().
So the expression sizeof(a) will become sizeof (int *) which results in 4 or 8 depending on machine 32 bit or 64 bit.
Here it is mentioned that on 64 bit machine so it will return 8.
@codingo1234
I am also haiving same doubt
int a[10] mean we have allocated 10 Bytes from memory may or may not be consecutive
but a[60] how it give 0 ??