C sizeof char pointer

后端 未结 5 1042
感动是毒
感动是毒 2021-01-07 08:41

Why is size of this char variable equal 1?

int main(){

char s1[] = \"hello\";

fprintf(stderr, \"(*s1) : %i\\n\", sizeof(*s1) )    // prints out 1

}
         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-07 09:22

    sizeof(*s1) means its denotes the size of data types which used. In C there are 1 byte used by character data type that means sizeof(*s1) it directly noticing to the character which consumed only 1 byte.
    
    If there are any other data type used then the **sizeof(*data type)** will be changed according to type.
    

提交回复
热议问题