这个C程序里都有什么

来源:百度知道 编辑:UC知道 时间:2024/07/06 14:00:18
#include<stdio.h>
#include<stdlib.h>
#include<string.h>//提供strlen()函数的原形
#define PRAISE "What a super marvelous name!"
int main(void)
{
char name[40];

printf("What's your name?\n");
scanf("%s",name);
printf("Hello,%s,%s\n",name,PRAISE);
printf("Your name of %d letters occupies %d menory cells.\n",
strlen (name),sizeof name);
printf("The phrase of praise has %d letters",
strlen(PRAISE));
printf("and ocupies %d memorycells.\n", sizeof PRAISE);
system("pause");
}

strlen(PRAISE)); sizeof PRAISE
为什么,有strlen(PRAISE)加括号,
sizeof PRAISE 这个没有括号,
sizeof,从哪来的,

strlen(x)表示求x的字符串长度
sizeof表示变量定义的空间大小。
比如:
char x[80] = "hello"; 表示分配一个80个字节长的指针,初始值填写hello,所以sizeof x会返回80,strlen(x)等于hello字符串长度,5