When you write size(ar)
then you're passing a pointer and not an array.
The size of a pointer and an int is 4 or 8 - depending on ABI (Or, as @H2CO3 mentioned - something completely different), so you're getting sizeof(int *)/sizeof int
(4/4=1 for 32-bit machines and 8/4=2 for 64-bit machines), which is 1 or 2 (Or.. something different).
Remember, in C when pass an array as an argument to a function, you're passing a pointer to an array.
If you want to pass the size of the array, you should pass it as a separated argument.