int main() { char str1[] = {'h','e','l','l','o'}; char str2 = "hello";//'\0' int len1 = sizeof(str1)/sizeof(char); //5 int len2 = sizeof(str2)/sizeof(char); //6 printf }
字符串是以'\0'为结束标志,所以在计算字符串长度时,它的长度为6
如果想用字符数组表示字符串,应像如下定义
char str1[6] = {'h','e','l','l','o','\0'};标签:字符,int,str1,char,数组,字符串,sizeof From: https://www.cnblogs.com/zj-studyrecoding/p/17281563.html
因为像stycpy、strcmp函数都是以'\0'标志来判断结束的