strlen和sizeof的区别与总结

strlen是用来计算字符串的长度,遇到第一个NULL('\0')为止,不包括‘\0’。 sizeof是用来计算变量或者对象、类型所占字节的多少。 首先来看一个例子: char s1[] = "hello"; char* s2 = "hello"; char s3[10] = ''hello"; sizeof(s1) = 5               strlen(s1) = 5 sizeof(
相关文章
相关标签/搜索