sizeof(表达式) 是C/C++关键字(不是函数)。
功能:返回“表达式”结果所占机器“字节”的大小。
strlen(字串) 是C/C++标准库的函数(不是关键字),在头文件string.h中声明。
功能:计算“字串”中的'/0'之前的字符个数。
特别注意:strlen总是假定传给它的参数是以null结束符'/0'结尾的,所以如果传给strlen的参数不是以'/0'结尾的话,strlen会一直计算长度知道遇到'/0',所以在给strlen传参时要特别注意。
很多人觉得sizeof和strlen对于一个字符“数组”运算后的结果“差不多”,那是因为在现在的X86计算机中,一个ASCII字符刚好是一个机器“字节”。
NAME
strlen - calculate the length of a string
SYNOPSIS
#include <string.h>
size_t strlen(const char *s);
DESCRIPTION
The strlen() function calculates the length of the string s, not
including the terminating '/0' character.
RETURN VALUE
The strlen() function returns the number of characters in s.
CONFORMING TO
SVr4, 4.3BSD, C89, C99.
SEE ALSO
string(3), wcslen(3), wcsnlen(3)