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.
Working with arrays - C Tutorial
From the course: Complete Guide to C Programming Foundations
Working with arrays
- [Instructor] In This code, float array highscore has five elements. Lines seven through 11 set the array element values. Each element referenced like an individual float variable. Likewise in lines 14 through 18, each element of the array is used as an individual float variable, but they're repetitive, which really isn't a good thing, not a good programming practice. The code can be streamlined by adding a loop. Looping variable must be declared, and the for loop would go right after this puts statement. For (x=0), the first element of the array is zero. This loop will repeat five times. Now modify the printf statement to output the values and get rid of these. The number also needs to be addressed. And for the number output, I'm going to use x+1, because remember, x starts at zero. Let's run the code to make sure it all works. And there are the five values. When I look at the code, more streamlining is possible. The assignments can be made when the array is declared. They don't…
Contents
-
-
-
-
-
-
-
-
Understanding arrays2m 48s
-
(Locked)
Working with arrays2m 51s
-
(Locked)
Challenge: Creating an array55s
-
(Locked)
Solution: Creating an array1m 41s
-
(Locked)
Passing an array to a function2m 45s
-
(Locked)
Working with multi-dimensional arrays2m 42s
-
(Locked)
Building a structure3m 31s
-
(Locked)
Nesting structures3m 17s
-
(Locked)
Challenge: Constructing a structure1m 3s
-
(Locked)
Solution: Constructing a structure3m 5s
-
(Locked)
Putting structures into an array2m 37s
-
(Locked)
Working with structures and functions3m 47s
-
(Locked)
Chapter challenge: Manipulating a structure1m 22s
-
(Locked)
Chapter solution: Manipulating a structure2m 4s
-
-
-
-
-
-