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

Modifying arrays - C Tutorial

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

Start my 1-month free trial

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…

Contents