本帖最后由 王雪冬 于 2014-4-16 17:42 编辑
看下面的代码:- @interface Car : NSObject
- {// 成员变量
- @public
- int wheels;
- int speed;
- }
- - (void)run;
- @end
- @implementation Car
- - (void)run
- {
- NSLog(@"%d个轮子,速度为%dkm/h的车子跑起来", wheels, speed);
- }
- @end
- void test1(Car *newC)
- {
- newC->wheels = 5;
- }
- void test2(Car *newC)
- {
- Car *c2 = [Car new];
- c2->wheels = 5;
- c2->speed = 300;
-
- newC = c2;
- newC->wheels = 6;
- }
- int main()
- {
- Car *c = [Car new];
- c->wheels = 4;
- c->speed = 250;
-
- test2(c);
-
- [c run];
-
- return 0;
- }
复制代码
问什么执行完[c run]
打印出来的 wheel=4 speed=200 。而没有重新赋值呀?
|