sizeof在c语言中是什么意思

如题所述

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


int a=10;

int arr=[1,2,3];

char str[]="hello";

int len_a = sizeof(a);

int len_arr = sizeof(arr);

int len_str = sizeof(str)

printf("len_a=%d,len_arr=%d,len_str=%d\n",len_a,len_arr,len_str)

结果是:len_a=4,len_arr=12,len_str=6

扩展资料:

在 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.



参考资料:

百度百科-sizeof

温馨提示:答案为网友推荐,仅供参考
相似回答