20.09.2015 Views

Programming in C

Kochan - ProgramminginC

Kochan - ProgramminginC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

242 Chapter 11 Po<strong>in</strong>ters<br />

Program 11.4 Us<strong>in</strong>g Po<strong>in</strong>ters to Structures<br />

// Program to illustrate structure po<strong>in</strong>ters<br />

#<strong>in</strong>clude <br />

<strong>in</strong>t ma<strong>in</strong> (void)<br />

{<br />

struct date<br />

{<br />

<strong>in</strong>t month;<br />

<strong>in</strong>t day;<br />

<strong>in</strong>t year;<br />

};<br />

struct date today, *datePtr;<br />

datePtr = &today;<br />

datePtr->month = 9;<br />

datePtr->day = 25;<br />

datePtr->year = 2004;<br />

pr<strong>in</strong>tf ("Today's date is %i/%i/%.2i.\n",<br />

datePtr->month, datePtr->day, datePtr->year % 100);<br />

}<br />

return 0;<br />

Program 11.4 Output<br />

Today's date is 9/25/04.<br />

Figure 11.2 depicts how the variables today and datePtr would look after all of the<br />

assignment statements from the preced<strong>in</strong>g program have been executed.<br />

datePtr<br />

today<br />

.month<br />

.day<br />

.year<br />

9<br />

25<br />

2004<br />

Figure 11.2<br />

Po<strong>in</strong>ter to a structure.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!