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

Creating an array of structures - C Tutorial

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

Start my 1-month free trial

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…

Contents