首先看一MSDN上如何对sizeof进行定义的:sizeof Operatorsizeof eXPRessionThe sizeof keyWord gives the amount of storage, in bytes, associated with a variable or a type (including aggregate types). This keyword returns a value of type size_t.The expression is either an identifier or a type-cast expression (a type specifier enclosed in parentheses).When applied to a strUCture type or variable, sizeof returns the actual size, which may include padding bytes inserted for alignment. When applied to a statically dimensioned array, sizeof returns the size of the entire array. The sizeof operator cannot return the size of dynamically allocated arrays or external arrays.然后再看一下对strlen是如何定义的: strlenGet the length of a string.Routine Required Header:strlen <string.h>size_t strlen( const char *string );Parameterstring:Null-terminated string LibrariesAll versions of the C run-time libraries.Return ValueEach of these functions returns the number of characters in string, excluding the terminal NULL. No return value is reserved to indicate an error.RemarksEach of these functions returns the number of characters in string, not including the terminating null character. wcslen is a wide-character version of strlen; the argument of wcslen is a wide-character string. wcslen and strlen behave identically otherwise.二、由几个例子说开去。
3.sizeof可以用类型做参数,strlen只能用char*做参数,且必须是以///////////////'///////////////'////////////////0///////////////'///////////////'结尾的。sizeof还可以用函数做参数,比如: short f();printf("%d////////////////n", sizeof(f()));输出的结果是sizeof(short),即2。