C语言 strlen()和 sizeof()的区别
(2017-10-27 06:51:22)
标签:
c语言strlen()和sizeo
strlen()
sizeof()
strlen()和sizeof()的
分类:
C
The previous chapter unleashed the sizeof operator, which gives the
size of things in bytes.The strlen() function gives the length of a
string in characters. Because it takes one byte to hold one
character, you might suppose that both would give the same result
when applied to a string, but they don’t.
#include
#include
#define PRAISE "You are an extraordinary being."
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 %d letters occupies %d memory cells.\n",
strlen(name), sizeof name);
printf("The phrase of praise has %d letters ",
strlen(PRAISE));
printf("and occupies %d memory cells.\n", sizeof PRAISE);
return 0;
}
分享:
喜欢
赠金笔
加载中,请稍候......
评论加载中,请稍候...
发评论
登录名: 密码: 找回密码 注册记住登录状态
昵 称:
评论并转载此博文
发评论
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。