From the course: Complete Guide to C Programming Foundations
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Putting structures into an array - C Tutorial
From the course: Complete Guide to C Programming Foundations
Putting structures into an array
- [Instructor] Just like other data types in C, you can create an array of structures. Each element in the array is its own structure with its own members, as shown in this code. The pixel structure has three members, integers, horz, and vert, and character color. The next statement creates a pixel structure array named box with four elements. Then you see way too many statements that set data for each structure member in the array. The variable is formatted with the array name first, box. Next are the square brackets with the element number, zero for the first element in the array, then comes a dot and the structure member. Finally comes the assignment. For each member of the first element, box zero is used. Then comes box one, box two, and box three for each of the four elements in the array. A for loop outputs all the elements contents. Run to see the exciting output, and there you go. Because all these values are known, you can easily assign them when the array is declared. This…
Contents
-
-
-
-
-
-
-
-
Understanding arrays2m 48s
-
(Locked)
Working with arrays2m 51s
-
(Locked)
Challenge: Creating an array55s
-
(Locked)
Solution: Creating an array1m 41s
-
(Locked)
Passing an array to a function2m 45s
-
(Locked)
Working with multi-dimensional arrays2m 42s
-
(Locked)
Building a structure3m 31s
-
(Locked)
Nesting structures3m 17s
-
(Locked)
Challenge: Constructing a structure1m 3s
-
(Locked)
Solution: Constructing a structure3m 5s
-
(Locked)
Putting structures into an array2m 37s
-
(Locked)
Working with structures and functions3m 47s
-
(Locked)
Chapter challenge: Manipulating a structure1m 22s
-
(Locked)
Chapter solution: Manipulating a structure2m 4s
-
-
-
-
-
-