From the course: C: Data Structures, Pointers, and File Systems
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Creating an array of structures - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
Creating an array of structures
- [Instructor] Just like any type of variable in C you can create an array of structures. Each structure becomes an element in the array. The only tricky part is how you reference the structure members within the array. In this code the pixel structure is defined in line five. It has three members, integers, horz, and vert. And a character color. The next line 10 creates a pixel structure variable box. This is an array variable with four elements. Then several rows of code fill each array element and structure member. First comes element 0, the first element of the array. Check the notation. The variable name is followed by the brackets and the array number. The key to remembering this format is to check how the variable was declared in line 10. The brackets follow the variable name not the member name. Then for each member of the first element box zero is used. In box one, box two and box three, three members for each of the four elements of the array makes for 12 lines of code. When…
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
-
Working with arrays3m 5s
-
Modifying arrays3m 11s
-
Passing an array to a function3m 17s
-
Working multi-dimensional arrays3m 2s
-
Building a structure3m 23s
-
Nesting structures2m 56s
-
Creating an array of structures2m 28s
-
Sending a structure to a function3m 36s
-
Understanding a union2m 47s
-
Challenge: Presidents of the U.S.A.1m 38s
-
Solution: Presidents of the U.S.A.2m 52s
-
-
-
-
-
-