C语言关键字const

来源:互联网 发布:手机怎么举报淘宝卖家 编辑:程序博客网 时间:2024/04/28 16:14

C语言关键字const

Part 1 变量定义部分

constint value01 = 100;

// error information: assignment of read-only variable 'value01'

// value01 = 111;


intconst value02 = 200;

// error information: assignment of read-only variable 'value02'

// value02 = 222;


int value03 = 300;

int value04 = 400;

constint *pointer01 = &value03;

// error information: assignment of read-only location

// *pointer01 = 111;

pointer01 = &value04;


intconst *pointer02 = &value03;

// error information: assignment of read-only location

// *pointer02 = 222;

pointer02 = &value04;


int*const pointer03 = &value03;

*pointer03 = 333;

// error information: assignment of read-only variable 'pointer03'

// pointer03 = &value04;


constint*const pointer04 = &value03;

// error information: assignment of read-only location

// *pointer04 = 444;

// error information: assignment of read-only variable 'pointer04'

// pointer04 = &value04;



原创粉丝点击