The use of sizeof in C

本文详细介绍了C语言中的sizeof运算符,解释了它如何用于确定变量或类型的内存占用大小,并通过示例展示了如何使用sizeof来计算数组元素的数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The definition of sizeof is bellow

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.

So, first sizeof is a keyword in C. And the sizeof can show the size of a data type and data structure in memory.

For example

#include <stdio.h>
int main(){
int a[]={1,3,4,5};
printf("%d",sizeof (a)/sizeof(a[0]));
}

The result of this program is 4

It has been shown that sizeof(a) is 16 which a is int array that contains 4 elements. And the sizeof (a[0]) is 4. 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值