C语言求字符串长度
strlen():返回的是直接可观察到的字符数量
sizeof():返回的是实际内存空间,默认情况下,也计算结束符’\0’
#include <stdio.h>
#include <string.h>
int main(){
char str[] = "hello world!";
printf("%d\n" ,sizeof(str)); // 13 多了'\0 '
printf("%d\n" ,strlen(str)); // 12
char str1[20] = "hello world!";
printf("%d\n" ,sizeof(str1)); // 20
printf("%d\n" ,strlen(str1)); // 12
}