From the course: C: Data Structures, Pointers, and File Systems

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Nesting structures

Nesting structures - C Tutorial

From the course: C: Data Structures, Pointers, and File Systems

Start my 1-month free trial

Nesting structures

- [Instructor] A structure can hold any variable type as a member. And this rule includes other structures, what I call nested structures. So in this exercise file, you see two structures. The first, date, holds three members, integers month day and year. The second, person, holds two members. The first is a date structure referenced as birthday. The second is a character array a string name. See how the structure member at line 12 is defined like any variable? The struct keyword comes first, then the structure definition date, and then the variable name birthday. At line 15, a person structure variable, president is declared. Lines 17 through 20 fill the members of the president structure variable. For a nested structure two dots are used to reference the inner member. President.birthday refers to the birthday member, and the .month refers to the month member inside the nested structure. At line 20 you see the string copy function used, which assigns a string to the name member of…

Contents