码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 里const在修饰对象时候的用法

时间:2018-03-20 15:55:00      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:bsp   gpo   其他   color   就是   nss   span   class   用法   

/*
 ---------- const NSString *str1 = @"123" ----------
| 0x123456  str  --- 0x654321  || 123 ---- 0x654321 | // const 修饰的是 *str, 而*str 是值, 所以const 修饰的就是值123
|           str  --- 0x654221  || ads ---- 0x654221 | // 因为const 修饰的是值 所以 指针str 还是可变的(可以指向其他值)

 ---------- NSString const *str2 = @"456" ----------
| 0x123464  str2  --- 0x654311 || 456 ---- 0x654311 | // 与上面同理
|           str2  --- 0x654211 || zxc ---- 0x654211 |

 ---------- NSString* const str3 = @"789" ----------
| 0x123478  str3  --- 0x654301 || 789 ---- 0x654301 | // const 修饰的是 str3, 而str3 是指针(指向的是值的地址),
|                              ||                   |    所以const 修饰的就是值789 的地址值
| 0x123478  str3  --- 0x654301 || qwe ---- 0x654201 | // 因为const 修饰的是指针(指向的是值的地址)
|                              ||                   |    所以 指针str3 是不可变的(不可以指向其他地址)
------------------------------------------------------
*/

 

iOS 里const在修饰对象时候的用法

标签:bsp   gpo   其他   color   就是   nss   span   class   用法   

原文地址:https://www.cnblogs.com/MrTao/p/8609621.html

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