gpt4 book ai didi

c - sizeof(name) 和 sizeof name 的区别

转载 作者:太空宇宙 更新时间:2023-11-04 05:22:51 25 4
gpt4 key购买 nike

<分区>

我正在学习 C primer plus 并遇到以下示例:

#include <stdio.h>
#include <string.h> //provide strlen() prototype
#define PRAISE "You are an extraordinary being with a big big brain."
int main(void)
{
char name[40];

printf("What's your name? ");
scanf("%s", name);
printf("Hello, %s. %s\n", name, PRAISE);
printf("Your name of %zd letters occupies %zd memory cells.\n", strlen(name), sizeof name);
printf("Size of the name %zd", sizeof(name));

return 0;
}

编译运行:

$ ./a.out
What's your name? Trump
You are an extraordinary being with a big big brain."
Your name of 5 letters occupies 40 memory cells.
Size of the name 40

令我困惑的是 sizeof(name)sizeof name 相同?

sizeof() 是一个库例程,但是如何与 sizeof 联系起来,它就像在命令行中一样是谓词和参数。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com