Objective-C構文のポインタ型パラメータ
8372 ワード
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