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

Working with arrays - C Tutorial

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

Start my 1-month free trial

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…

Contents