前面我刚刚介绍完
Objective-C分行文字输出,在这里就说明下如何
显示变量的值
01 #import <Foundation/Foundation.h>
02
03 int main (int argc, const char * argv[])
04 {
05 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
06
07 int sum;
08
09 sum = 50 + 25;
10 NSLog(@"The sum of 50 and 25 is %i", sum);
11 [pool drain];
12
13 return 0;
14 }
02
03
04
05
06
07
08
09
10
11
12
13
14
NSLog(@"The sum of 50 and 25 is %i", sum);
这句中的百分号是一个特殊字符,在
Objective-C语言中,它可被NSLog函数识别。紧跟在百分号后的字符指定在这种情况下将要显示的值的类型。这里的i表示整数
代码运行后的结果如下
The sum of 50 and 25 is 75
范例2-5,稍微增加些变化,定义了两个value变量来存储两个数50和25,接下来将两个value变量相加后存入整型变量sum,用NSLog输出这个值。
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
最终的输出结果和2-4同