Why sizeof(array) and sizeof(&array[0]) gives different results?

前端 未结 8 967
悲&欢浪女
悲&欢浪女 2020-12-30 06:56
#include 
int main(void){
    char array[20];

    printf( \"\\nSize of array is %d\\n\", sizeof(array) );  //outputs 20
    printf(\"\\nSize of &         


        
8条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-30 07:45

    &array[0] returns a pointer to the first index of array. Using the sizeof operator on a pointer will yield the size of a pointer (depends on ABI), in your case, it's 4.

提交回复
热议问题