> 教育经验 > c语言sizeof什么意思

c语言sizeof什么意思

c语言sizeof什么意思

sizeof是C语言中保留关键字,也可以认为是一种运算符,单目运算符。常见的使用方式

int a=10;

int arr=[1,2,3];

char str[]=\"hello\";

int len_a = sizeof(a);

int len_arr = sizeof(arr);

在 Pascal 语言中,sizeof() 是一种内存容量度量函数,功能是返回一个变量或者类型的\'大小(以字节为单位)。

在 C 语言中,sizeof() 是一个判断数据类型或者表达式长度的运算符。

在Pascal 语言与C语言中,对 sizeof() 的处理都是在编译阶段进行。

sizeof是C/C++中的一个操作符(operator),简单的说其作用就是返回一个对象或者类型所占的内存字节数。

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.