原地址:http://www.vckbase.com/index.php/wv/789点击打开链接
http://blog.csdn.net/freefalcon/article/details/54839
http://www.cnblogs.com/chengxin1982/archive/2009/01/13/1374575.html
http://blog.csdn.net/shimazhuge/article/details/8238038
结合了几篇博文,一起总结了sizeof的问题。
关于sizeof的问题,并且本人对这个问题也一直没有得到很好的解决,索性今天对它来个较为详细的总结,同时结合strlen进行比较,如果能对大家有点点帮助,这是我最大的欣慰了。
一、好首先看看sizeof和strlen在MSDN上的定义:
首先看一MSDN上如何对sizeof进行定义的:
01.
sizeof
Operator
02.
03.
sizeof
expression
04.
05.
The
sizeof
keyword gives the amount of storage, in bytes, associated with a variable or a type
06.
(including aggregate types). This keyword returns a value of type
size_t
.
07.
08.
The expression is either an identifier or a type-cast expression (a type specifier enclosed in
09.
parentheses).
10.
11.
When applied to a structure type or variable,
sizeof
returns the actual size, which may include
12.
padding bytes inserted
for
alignment. When applied to a statically dimensioned array,
sizeof
13.
returns the size of the entire array. The
sizeof
operator cannot
return
the size of dynamically
14.
allocated arrays or external arrays.
然后再看一下对strlen是如何定义的:
01.
strlen
02.
03.
Get the length of a string.
04.
05.
Routine Required Header:
06.
strlen
<string.h>
07.
08.
size_t
strlen
(
const
char
*string );
09.