strlrn 计算字符串的长度时不会将'\0'计入在内,而sizeof会将'\0'计入在内。
#include <stdio.h>
void main()
{
static char string[20]="abcde";
printf("%d \n",strlen(string));
printf("%d \n",sizeof(string));
}
运行:
5
20
Press any key to continue
strlrn 计算字符串的长度时不会将'\0'计入在内,而sizeof会将'\0'计入在内。
#include <stdio.h>
void main()
{
static char string[20]="abcde";
printf("%d \n",strlen(string));
printf("%d \n",sizeof(string));
}
5
20
Press any key to continue