Pointers and Structures

You have seen how to define a pointer to point to a basic data type such as an int or a char. But you can also define a pointer to point to a structure. Earlier in this chapter, you defined your date structure as follows:

struct date{   int month;   int day;   int year;} ;

Just as you defined variables to be of type struct date, as in

struct date  todaysDate;

you can define a variable to be a pointer to a struct date variable:

struct date *datePtr;

You can then use the variable datePtr, as just defined, in the expected fashion. For example, you can set it to point to todaysDate with the following assignment statement:

datePtr = &todaysDate;

After such an assignment, you can indirectly access any of the members of the ...

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.