从0开始学习OC程序-第2天

对象和函数

基本数据类型,赋值改的是本身
引用数据类型,赋值改的是指针

#import <Foundation/Foundation.h>

@interface Car : NSObject
{
    @public
    int wheels;
    int speed;
}
-(void)run;
@end

@implementation Car

-(void)run{
    NSLog(@"汽车有%d个轮子,时速是%dkm/h",wheels,speed);
}

@end

void configWheelsAndSpeed(int wheels,int speed){
    wheels = 3;
    speed = 100;
}

void configCar(Car *car){
    car->wheels = 3;
    car->speed = 100;
}

int main(){

    Car *car = [Car new];
    car->wheels = 4;
    car->speed = 240;

    configWheelsAndSpeed(car->wheels,car->speed);

    [car run];

    configCar(car);

    [car run];

    return 0;
}

你可能感兴趣的:(oc)