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

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

    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.

提交回复
热议问题