0
点赞
收藏
分享

微信扫一扫

通过const 修饰,不让其被随意修改

白衣蓝剑冰魄 2022-12-14 阅读 133

#include<stdio.h>

#include<string.h>

#include<assert.h>


int main()

{

//const 修饰变量,这个变量就称为常变量,不能被修改,但是本质上还是变量

const int num = 10;


const int * p = &num;//如果放在*的左边,修饰的是*p,表示指针指向的内容,不能通过指针来修改

*p = 20;

printf("%d\n",num);



 return 0;

}


举报

相关推荐

0 条评论