From the course: C: Data Structures, Pointers, and File Systems
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Working with arrays - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
Working with arrays
- [Instructor] This code shows how to create, fill and display an array with five elements. The array highscore is declared at line five. It has five elements each of which is a float data type. The next five lines seven through 11 fill individual array elements with values. In these assignments, the elements are references just as if each were an individual float variable. Likewise in lines 14 through 18, each element of the array is used as individual float variables. Build and run. I hope you noticed a way to improve this code. See the repetitive lines? In this code, I've added integer variable x at line six. The loop at line 15 uses this variable to display the values in the highscore array which is far more efficient than doing things one line at a time. See how the loop increments variable x from zero through four at line 15. It's common for C language loops to start counting at zero which plays nicely with arrays which have zero as the first element. Still, for human eyes, one…
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
-
-
-
-
-
-