/*
int const *p; *p是常量, p是变量
const int *p; *p是常量, p是变量 int * const p; *p是变量, p是常量 const int * const p; *p是常量, p是常量 int const * const p; *p是常量, p是常量
*/ #import <Foundation/Foundation.h>
#import <objc/runtime.h> /**
const的作用
1.const只修饰它右边的内容
2.被const修饰的变量是只读的(变量 -> 只读变量[常量])
*/
void testAge(const int *p); int main(int argc, const char * argv[]) {
@autoreleasepool {
int age = ; testAge(&age); NSLog(@"%d", age);
}
return ;
} void testAge(const int *p)
{
NSLog(@"%d", *p);
} void test()
{
// 常量(只读变量)
// const int age = 20;
// int const age = 20; // 定义int类型的变量
int a = ;
int age = ;
int money = ; // 定义指针变量 : 将来只能指向int类型的变量(只能存储int类型变量的地址)
int const * const p = &a; // 指针变量p 指向 age
// p = &age;
// *p = 90;
//
// // 指针变量p 指向 money
// p = &money;
// *p = 90; NSLog(@"%d %d", age, money);
}

oc const 关键字 对指针的理解的更多相关文章

  1. const关键字与指针

    const与指针在一起的几种情况. const int *p1; //表示p1本身不是const,指向的变量是const. const *int p2; //语法错误 int const *p3; / ...

  2. C语言const关键字的作用

    1 #define _CRT_SECURE_NO_WARNINGS 2 #include <stdio.h> 3 #include <string.h> 4 #include ...

  3. const关键字与数组、指针

    目录 const关键字 const修饰数组 const修饰指针 用两个const修饰指针 @ 开始回顾C基础知识.C中使用指针是很危险的事情,一个不慎就会造成程序崩溃,因此对于传入函数的参数进行保护就 ...

  4. 实习第一个月总结(const关键字、条件编译、volatile关键字、#和##的作用、函数指针)

    C语言中const关键字的作用: 修饰局部变量或者全局变量,表示变量n的值不能被改变了 修饰指针,分为常量指针与指针常量,也可以两者结合 常量指针指向的值不能改变,但是这并不是意味着指针本身不能改变, ...

  5. C++ 二级指针与 const 关键字

    可用七种不同的方式将 const 关键字用于二级指针,如下所示: //方式一:所指一级指针指向的数据为常量,以下几种为等效表示 const int ** pptc; //方式一 int const * ...

  6. C++中const关键字 理解

    const:符号常量  使用符号常量写出的代码更容易维护:指针是边读边移动,而不是边写边移动,许多函数参数是只读不写的. const最常见用途是作为数组的界和switch分情况标号(也可以用枚举符代替 ...

  7. c++中的const关键字的理解

    看effective c++第二版推荐使用const,少用define.今天才发现发现这远远不够. #define定义的常量在预处理替换,debug的时候无法打印宏的,这种常量设置是有缺陷的, con ...

  8. 关于C++指针、引用和const关键字的各种关系

    #include <stdio.h> #include<iostream> using namespace std; typedef char *new_type; int m ...

  9. Const关键字

    const const是一个C语言的关键字,它限定一个变量不允许被改变.使用const在一定程度上可以提高程序的安全性和可靠性.另外,在观看别人代码的时候,清晰理解const所起的作用,对理解对方的程 ...

随机推荐

  1. arduino 字符解析

    Arduino String.h库函数详解   此库中包含1 charAT()2 compareTo()3 concat()4 endsWith()5 equals()6 equalslgnoreCa ...

  2. android 蓝牙开发---与蓝牙模块进行通讯 基于eclipse项目

      2017.10.20 之前参加一个大三学长的创业项目,做一个智能的车锁App,用到嵌入式等技术,App需要蓝牙.实时位置等技术,故查了几篇相关技术文章,以此参考!             //先说 ...

  3. 计算型属性 vs 懒加载

    只实现 getter 方法的属性被称为计算型属性,等同于 OC 中的 ReadOnly 属性 计算型属性本身不占用内存空间 不可以给计算型属性设置数值 计算型属性可以使用以下代码简写 var titl ...

  4. context switch

    In computing, a context switch is the process of storing and restoring the state (more specifically, ...

  5. Exception Information

    https://developer.apple.com/library/content/technotes/tn2004/tn2123.html Exception Information The t ...

  6. ThinkPHP---thinkphp控制器、路由、分组设置(C)

    配置文件分3类:系统配置文件,分组配置文件,应用配置文件 ①系统配置文件ThinkPHP/Conf/convention.php: ②分组 / 模块 /平台配置文件Home/Conf/config.p ...

  7. oracle查询没有主键的表

    select table_name from user_tables a where not exists (select * from user_constraints b where b.cons ...

  8. react-router 4.x 路由按需加载

    react-router 4 代码分割(按需加载) 官方文档  https://serverless-stack.com/chapters/code-splitting-in-create-react ...

  9. for循环,字典遍历(一)

    #items(): 返回字典中所有 key.value #keys(): 返回字典中所有 key 的列表 #values():返回字典中所有 value 的列表 my_dict = {'语文':89, ...

  10. spark学习(1)---dataframe操作大全

    一.dataframe操作大全 https://blog.csdn.net/dabokele/article/details/52802150 https://www.jianshu.com/p/00 ...