#import <Foundation/Foundation.h>
//Student
//iPhone --> IPhone
//日期的结构体
typedef struct {
//年
int year;
//月
int month;
//日
int day;
}MyDate;
//Student类的声明
@interface Student : NSObject
{
@public
//学生姓名
NSString *_name;
//学生生日
MyDate _birthday; //结构体变量
//MyDate1 *md = [MyDate new];
//
// MyDate1 *_birthday;
}
@end
//Student类的实现
@implementation Student
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
Student *stu = [Student new];
stu->_name = @"凤姐";
// struct Car{
//
// int lunzi;
// int speed;
//
// }car1;
//
// car1 = (struct Car){4,50};
//
// int a[3]={4,50};
//第一种方法
stu->_birthday =(MyDate){1983,12,12};
//NSLog(@"%d,%d,%d",stu->_birthday.year,stu->_birthday.month,stu->_birthday.day);
//第二种方法:定义一个结构体变量
MyDate d1 = {1981,11,11}; //定义结构体变量的同时进行初始化
stu->_birthday = d1;
// NSLog(@"%d,%d,%d",stu->_birthday.year,stu->_birthday.month,stu->_birthday.day);
//MyDate d2 = d1;
//第三种方法,逐个赋值
stu->_birthday.year = 2014;
stu->_birthday.month = 12;
stu->_birthday.day = 11;
NSLog(@"%d,%d,%d",stu->_birthday.year,stu->_birthday.month,stu->_birthday.day);
}
return 0;
}
|
|