c语言宽度限定词,C语言中限定词的深层分析

Let’s look at what is meant when const

is used. It’s really quite simple:

const means that something is not

modifiable, so a data object that is

declared with const as a part of its

type specification must not be

assigned to in any way during the run

of a program. It is very likely that

the definition of the object will

contain an initializer (otherwise,

since you can’t assign to it, how

would it ever get a value?), but this

is not always the case. For example,

if you were accessing a hardware port

at a fixed memory address and promised

only to read from it, then it would be

declared to be const but not

initialized.

Taking the address of a data object of a type which isn’t const and putting it into a pointer to the const-qualified version of the same type is both safe and explicitly permitted; you will be able to use the pointer to inspect the object, but not modify it. Putting the address of a const type into a pointer to the unqualified type is much more dangerous and consequently prohibited (although you can get around this by using a cast). For example…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值