zoukankan      html  css  js  c++  java
  • Objective-C语法之指针型参数

    main.m

     1 #import <Foundation/Foundation.h>
     2 /**
     3  *  测试指针型参数和普通参数的区别
     4  *
     5  *  @param a 指针型参数
     6  *  @param b 普通参数
     7  *
     8  *  @return (指针型参数+2) + (普通参数+2)
     9  */
    10 int pointerTypeParameterTest(int *a, int b) {
    11     *a = *a + 2; //*a表示获取a变量指针(内存地址)所指向内存存储空间内的值
    12     b = b + 2;
    13     return *a+b;
    14 }
    15 int main(int argc, const char * argv[]) {
    16     @autoreleasepool {
    17         int a = 4;
    18         int b = 5;
    19         NSLog(@"a=%d, b=%d; &a=%p, &b=%p", a, b, &a, &b); //a=4, b=5; &a=0x7fff5fbff79c, &b=0x7fff5fbff798
    20         NSLog(@"pointerTypeParameterTest(&a, b)=%d", pointerTypeParameterTest(&a, b)); //pointerTypeParameterTest(&a, b)=13;&a表示获取a变量的内存地址,b表示获取变量的值
    21         NSLog(@"a=%d, b=%d; &a=%p, &b=%p, after the operation of pointerTypeParameterTest(&a, b)", a, b, &a, &b); //a=6, b=5; &a=0x7fff5fbff79c, &b=0x7fff5fbff798, after the operation of pointerTypeParameterTest(&a, b)
    22         
    23         
    24         int *c;
    25         c = &a;
    26         NSLog(@"c=%d, a=%d; &c=%p, c=%p, &a=%p", *c, a, &c, c, &a); //c=6, a=6; &c=0x7fff5fbff790, c=0x7fff5fbff79c, &a=0x7fff5fbff79c
    27         *c = 8;
    28         NSLog(@"c=%d, a=%d; &c=%p, c=%p, &a=%p", *c, a, &c, c, &a); //c=8, a=8; &c=0x7fff5fbff790, c=0x7fff5fbff79c, &a=0x7fff5fbff79c
    29     }
    30     return 0;
    31 }

    结果:

    1 2015-05-09 20:42:11.593 OCPointerTypeParameter[562:21474] a=4, b=5; &a=0x7fff5fbff79c, &b=0x7fff5fbff798
    2 2015-05-09 20:42:11.594 OCPointerTypeParameter[562:21474] pointerTypeParameterTest(&a, b)=13
    3 2015-05-09 20:42:11.594 OCPointerTypeParameter[562:21474] a=6, b=5; &a=0x7fff5fbff79c, &b=0x7fff5fbff798, after the operation of pointerTypeParameterTest(&a, b)
    4 2015-05-09 20:42:11.594 OCPointerTypeParameter[562:21474] c=6, a=6; &c=0x7fff5fbff790, c=0x7fff5fbff79c, &a=0x7fff5fbff79c
    5 2015-05-09 20:42:11.595 OCPointerTypeParameter[562:21474] c=8, a=8; &c=0x7fff5fbff790, c=0x7fff5fbff79c, &a=0x7fff5fbff79c
  • 相关阅读:
    django class类即视图类添加装饰器的几种方法
    django 如何在HMTL中使用媒体media_url
    django 对models中上传的文件或图片改名
    常用工具链接网址
    verifycode验证码模版
    shell 一些常用命令
    用 openresty 编写 lua
    centos7 安装python虚拟环境
    django url配置-反向解析-视图函数-HttpRequest对象-HttpResponse对象-cookies-session-redis缓存session
    PWN题搭建
  • 原文地址:https://www.cnblogs.com/huangjianwu/p/4574018.html
Copyright © 2011-2022 走看看