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

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