目录
一、sizeof()概念
sizeof()是 C 语言和 C++ 语言中的一个非常有用的运算符,用来确定变量或数据类型在内存中的大小。它返回的是以字节为单位的大小。这对于动态内存分配、数组、结构体和其他数据处理场景非常关键。
sizeof()在MSDN上的解释为:
The 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.
其返回值类型为size_t,在头文件stddef.h中定义。这是一个依赖于编译系统的值,一般定义为:
typedef unsigned int size_t;