Sizes of arrays declared with pointers

后端 未结 5 1713
走了就别回头了
走了就别回头了 2021-01-23 14:24
char c[] = \"Hello\";
char *p = \"Hello\";

printf(\"%i\", sizeof(c)); \\\\Prints 6
printf(\"%i\", sizeof(p)); \\\\Prints 4

My question is:

Why

5条回答
  •  礼貌的吻别
    2021-01-23 14:52

    "sizeof" is the directive of the compilers. The result indicates the size in memory that the argument occupies. Compiler is reseponsible for determining the result according to the argument's type. Regarding the "array", returns the array size. moreover, the pointer returns "4" generally speaking for 32-bit machine.

提交回复
热议问题