Behaviour of sizeof with string

前端 未结 2 1399
囚心锁ツ
囚心锁ツ 2021-01-20 03:36
‪#‎include‬ 
#include 
int main()
{
    printf(\"%d\\n\",sizeof(\"S\\065AB\"));
    printf(\"%d\\n\",sizeof(\"S65AB\"));
    printf(\"         


        
2条回答
  •  [愿得一人]
    2021-01-20 03:46

    A literal character string is an array of exactly the size needed to hold all the characters and an extra terminating zero-byte.

    So, "hello" has type char[6] and sizeof yields 6.

提交回复
热议问题