When you write size(a)
then you're passing a pointer and not an array. Since the size of a pointer and an int
is 4 or 8 (depending on ABI), you get sizeof(int *)/sizeof int
(4/4=1 for 32-bit machines and 8/4=2 for 64-bit ones) which is 1 or 2.
In C++ when pass an array as an argument to a function, actually you're passing a pointer to an array.