先看一下源代码
#include <stdio.h>
#include <string.h>
#define PRAISE "What a super marvelous name!"
int main(void)
{
char name [40];
printf("What is your name ?\n");
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;
}
下面是运行情况
问题是为什么输入的字符超过了 name的数组长度,而strlen函数给出的是正确的字符数,而sizeof给的是数组原长度,而且超过数组的部分怎么还能被是strlen正确计数?大神求解。