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

前端 未结 8 1016
悲&欢浪女
悲&欢浪女 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:46

    I think that "array" itself is constant pointer, you can not address it to different location. It is true that we can write: array is the same as &array[0], which is derived from &*(array+0) and it is equal to &*(array). We know that &* is eliminated so we are back to "array" again. So "array" is the same as "&*(array+0)" The terms should be the same in some circumstances, but it is not the same for the sizeof operator.

提交回复
热议问题