consider these two programs:
//////////////////////Program 1////////////
void print(int arr[])
{
int *p=arr;
cout<< sizeof(arr)<<endl; //// here it is 8
}
int main()
{
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};
print(arr);
return 0;
}
///////////////////////////// ///////////////////Program 2///////////
#include <stdio.h>
int main()
{
int arr[] = {10, 20, 30};
printf("%ld \n",sizeof(arr)); /// here it is 12
return 0;
}
////////////
arrhas decayed to a pointer type once it's been passed toprint. Sosizeofwithin that function yields the size of a pointer tointon your platform.In Program 2, that decay has not occurred: the type of
arris an array of 3ints. The size issizeof(int) * 3.