2012年5月25日 星期五

point and struct

refer to  Addison Wesley - Programming.in.ObjectiveC.2.0.2nd (2009)


// normal mode
struct date birthdays[15];  // normal mode

birthdays[1].month = 2;
birthdays[1].day  = 22;
birthdays[1].year = 1996;

// point mode
int main (int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
struct date
{
int month;
int day;
int year;
};
struct date today, *datePtr;  // point mode
datePtr = &today;
datePtr->month = 9;
datePtr->day = 25;
datePtr->year = 2009;
NSLog (@ ” Today ’ s date is %i/%i/%.2i. ” ,
datePtr->month, datePtr->day, datePtr->year % 100);
[pool drain];
return 0;
}

沒有留言: