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 - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Understanding arrays2m 59s
-
(Locked)
Working with arrays3m 5s
-
(Locked)
Modifying arrays3m 11s
-
(Locked)
Passing an array to a function3m 17s
-
(Locked)
Working multi-dimensional arrays3m 2s
-
(Locked)
Building a structure3m 23s
-
(Locked)
Nesting structures2m 56s
-
(Locked)
Creating an array of structures2m 28s
-
(Locked)
Sending a structure to a function3m 36s
-
(Locked)
Understanding a union2m 47s
-
(Locked)
Challenge: Presidents of the U.S.A.1m 38s
-
(Locked)
Solution: Presidents of the U.S.A.2m 52s
-
-
-
-
-
-