Arrays help remove repetitive chunks of code. Array values can be preset, just as values can be preset for any variable. A for loop is handy for displaying array element as it typically starts counting at zero just as array elements are numbered.
- [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. …
- Working with arrays
- Building a structure
- Creating an array of structures
- Testing characters
- Working with strings in C
- Using pointers to manipulate data
- Manipulating files
- Using command-line arguments
- Working with time functions
Skill Level Intermediate
1. Arrays and Structures
2. Characters and Strings
4. Files and the Operating System
5. The Interesting and Extraordinary
Next steps1m 52s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.