From the course: C: Data Structures, Pointers, and File Systems
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Modifying arrays - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
Modifying arrays
- [Instructor] Elements in an array operate like any individual variable. Modifying an array element is a familiar operation, though array notation may be new to you. In this code, the pet array is declared with four elements assigned, characters k, a, t, at line five. Because the assignment is a string literal, the compiler adds a null character as the fourth character and forth array element. At line eight, element zero is changed to letter c. Single quotes delineate the character literal value. Build and run. Cat and cat. Here you see an integer array, numbers. It's preset to five values. Lines 14, 15, and 16 swap two of the values. First, the value of the fourth element is saved in the temp variable. Next, the third element is placed into the fourth element, and last, the third element's value is set to temp's variable's value. The two for loops display the before and after values of the array. Build and run. And you see that values 88 and 100 are swapped between the before and…
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
-
(Locked)
Working with arrays3m 5s
-
(Locked)
Modifying arrays3m 11s
-
(Locked)
Passing an array to a function3m 17s
-
(Locked)
Working multi-dimensional arrays3m 2s
-
(Locked)
Building a structure3m 23s
-
(Locked)
Nesting structures2m 56s
-
(Locked)
Creating an array of structures2m 28s
-
(Locked)
Sending a structure to a function3m 36s
-
(Locked)
Understanding a union2m 47s
-
(Locked)
Challenge: Presidents of the U.S.A.1m 38s
-
(Locked)
Solution: Presidents of the U.S.A.2m 52s
-
-
-
-
-
-