summary: sizeof

本文详细解释了 C++ 中 sizeof 运算符的功能和用法,包括其如何应用于基本类型、引用、指针、数组及字符串等不同场景,并介绍了 C++11 新标准中对类成员使用 sizeof 的方法。

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

The result of applying sizeof depends in part on the type involved:

*) sizeof char or an expression of type char is guaranteed to be 1.

*) sizeof a reference type returns the size of an object of the referenced type.

*) sizeof a pointer returns the size needed hold a pointer.

*) sizeof a dereferenced pointer returns the size of an object of the type to which the pointer points; the pointer need not be valid.

*) sizeof an array is the size of the entire array. It is equivalent to taking the sizeof the lement type times the number of elements in the array. Note that sizeof does not convert the array to a pointer.

*) sizeof a string or a vector returns only the size of the fixed part of these types; it does not return the size used by the object's elements.

C++11:

Under the new standard, we can use the scope operator to ask for the size of a member of a class type. Ordinarily we can only access the members of a class through an object of that type. We don't need to supply an object, because sizeof does not need to fetch the member to know its size.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值