1. 使用间接
变量的间接可以使程序设计变得简单,负值修改只需要知道原来的定义地址便可。
例如:
//
// main.m
// indirect Using
//
// Created by macsir on 12-10-10.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import<Foundation/Foundation.h>
int main (int argc,const char * argv[])
{
// @autoreleasepool {
//
// // insert code here...
// NSLog(@"Hello, World!");
//
// }
// const char *words[4] = { "aardvark" , "abacus", "allude", "aygote"};
//注意此处得转意字符‘\’
const char *words[4] = {"joe-Bob \"Handyman\" Brown" ,
"Jacksonville \"Sly\" Murphy",
"Shinara Bain",
"George \"Guitar\" Books" };
int count = 100;
int wordCount = 4;
NSLog(@"The numbers from 1 to %d:", count);
int i;
// for(i = 1; i<= count; i++) {
// NSLog(@"%d\n", i);
// }
for(i = 0; i < wordCount; i++) {
NSLog(@"%s is %d characters long", words[i],strlen(words[i]));
}
return 0;
}
2. 间接介绍
int wordCount = 4;
NSLog(@"%s is %d characters long",words[i], strlen(words[i]));