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

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

    sizeof(&array[0]) is returning the size of a pointer to a char. array[0] yields a char, the & returns a pointer to the char. Your compiler used 4 bytes for a pointer (32 bit).

提交回复
热议问题