#include <stdio.h>
int main(void){
char array[20];
printf( "
Size of array is %d
", sizeof(array) ); //outputs 20
printf("
Size of &array[0] is %d
", sizeof(&array[0]); //output 4
}
Code above gives 20
for sizeof(array)
and 4
for sizeof(&array[0])
.
What I knew was instead of giving array as a argument, its first element can be passed. Shouldn't they give same output as 20? and why &array[0]
gives 4 as result? char is stored in 1 byte as far as I know?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…