0

why this program output 4

#define SIZE 10
void size(int arr[SIZE])
{
   printf("size of array is:%d\n",sizeof(arr));
}

 int main()
{
      int arr[SIZE];
      size(arr);
      return 0;
}

what hanppen when call size(arr) in main function, does mean that assign the address arr in the main function to arr[SIZE] in the size function?

can someone interpret this?

Rohan
  • 52,392
  • 12
  • 90
  • 87
steve
  • 608
  • 1
  • 5
  • 16

1 Answers1

1

Inside the function arr is a pointer. A pointer takes 4 bytes. sizeof returns the size of the variable passed as argument (in byte). That's why.

Shoe
  • 74,840
  • 36
  • 166
  • 272