C语言之const关键字修饰
2014-07-31 13:07
176 查看
//const
//const
修饰变量,把变量当做常量来看待,只能读不能写
// const int a = 10;
// a = 20; //只读变量不能赋值
int a =
10;
int b =
20;
//const修饰谁,谁就不可变
const
int *p = &a;
//const
修饰*p,不能通过指针变量p修改指向空间的内容,但是p可以重指向
// p = &b;
// *p = 20;
int
const *p1 = &a;
//const
修饰*p1,不能通过指针变量p1修改指向空间的内容,但是p1可以重指向
// p1 = &b;
// *p1 = 30;
int *
const p2 = &a;
//const
修饰p2,p2不可以重指向,但可以通过p2修改指向空间的内容
// p2 = &b;
// *p2 = 30;
const
int * const p3 = &a;
//const
修饰p3,以及*p3, p3 不可以重指向,也不可以通过p3修改指向空间的内容.
// p3 = &b;
// *p3 = 30;
// //const 让程序安全
// strlen(const char *) //strlen求得的是字符串的长度,我们不允许对字符串进行修改.
//const
修饰变量,把变量当做常量来看待,只能读不能写
// const int a = 10;
// a = 20; //只读变量不能赋值
int a =
10;
int b =
20;
//const修饰谁,谁就不可变
const
int *p = &a;
//const
修饰*p,不能通过指针变量p修改指向空间的内容,但是p可以重指向
// p = &b;
// *p = 20;
int
const *p1 = &a;
//const
修饰*p1,不能通过指针变量p1修改指向空间的内容,但是p1可以重指向
// p1 = &b;
// *p1 = 30;
int *
const p2 = &a;
//const
修饰p2,p2不可以重指向,但可以通过p2修改指向空间的内容
// p2 = &b;
// *p2 = 30;
const
int * const p3 = &a;
//const
修饰p3,以及*p3, p3 不可以重指向,也不可以通过p3修改指向空间的内容.
// p3 = &b;
// *p3 = 30;
// //const 让程序安全
// strlen(const char *) //strlen求得的是字符串的长度,我们不允许对字符串进行修改.
相关文章推荐
- c语言常用关键字 static,const,extern...
- 有关C语言中的关键字const
- C语言中Static和Const关键字的的作用
- C语言中关键字auto、static、register、const、volatile、extern的作用
- C语言指针(3)~const关键字与指针
- c语言中const volatile关键字 和 elf section的关系
- 黑马程序员———C语言———【函数指针、指针函数、野指针、内存管理、const关键字】
- C语言中关键字auto、static、register、const、volatile、extern的作用
- C语言中const关键字学习
- c语言的const关键字
- 总结C语言中const关键字的使用
- C语言的const关键字与指针搭配使用
- c语言中const关键字详解
- C语言的const关键字
- C语言笔记之const关键字
- C语言中Static和Const关键字的的作用
- C语言基础(8)-const,volatile,register关键字
- C语言中关键字auto、static、register、const、volatile、extern的作用
- C语言中Static和Const关键字的的作用
- C语言中的const关键字