码迷,mamicode.com
首页 > 其他好文 > 详细

【C基础】const用法

时间:2014-11-24 18:45:38      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:style   color   sp   strong   on   bs   ef   size   nbsp   

 

  1.const 和 define 异同

  同:const 和 define都是修饰常量

  :const修饰的常量只是编译器的一种优化,它是可以通过内存地址修改const修饰的常量;而define修饰的常量任何方式都不能修改

  2.int const a 和const int a 是一样的,都表示a 为常量

  3.const int * a 和 int * const a

  const int * a:  可以看做const 修饰的是 (int * ),表示指向的内存空间为常量,更清楚的解释就是:表示这片内存是只读的,不可写;  

  int * const a:可以看做const 修饰的是a这个指针,表示常量指针,不能随便更改常量指针(a)的指向。

 

【C基础】const用法

标签:style   color   sp   strong   on   bs   ef   size   nbsp   

原文地址:http://www.cnblogs.com/wangliu/p/4119287.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!