Initializing Structures
Initializing structures is similar to initializing arrays; the elements are simply listed inside a pair of braces, with a comma separating each element.
To initialize the date
structure variable today
to July 2, 2014, you can use this statement:
struct date today = { 7, 2, 2014 } ;
As with the initialization of an array, fewer values can be listed than the structure contains. So the statement
struct date today = { 7 } ;
sets today.month
to 7
but gives no initial value to today.day
or today.year
. In such a case, their default initial values are undefined.
Specific members can be designated for initialization in any order with the notation
.member = value
in the initialization list, as in ...
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.