有如下程序段:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char a[] = "xyz", b[] = {'x', 'y', 'z'};
if (strlen(a) > strlen(b))
printf("a > b\n");
else
printf("a <= b\n");
return (0);
}
则程序输出:









char a[] = "xyz", b[] = {'x', 'y', 'z'}; a容易理解,strlen(a)=3; b是数组,元素在内存中是连续存储的,而strlen函数求字符串长度是要以'\0'结尾,但是b没有'\0', strlen的内部函数指针会一直向后搜索,直至找到'\0',内存中的其他区域也是有数据的,只是没有意义, 所以,strlen的指针最后指到哪里无法确定,但是结果肯定大于等于3.