#include
int main(void){
char array[20];
printf( \"\\nSize of array is %d\\n\", sizeof(array) ); //outputs 20
printf(\"\\nSize of &
sizeof(array)
is giving you size of total array and sizeof(&array[0])
is giving you sizeof(char *)
Your question is perfect example of Array and pointer are not same
. Array may act as pointer.Have a look here.
The variable array
is an array of 20 char
, the value of the expression sizeof(array)
is equal to the sizeof bytes of an array of 20 chars
, which is 20
.
&array[0]
is a pointer. The sizeof
returns the size of a pointer, which is 4 in your machine.