Character arrays, strings, automatically have the null character appended as the final element in the array. To swap array elements, you need another variable, one of the same data type. Like any variable, an array's elements must be initialized before they're used. Arrays can be duplicated, providing the target array has at least as many elements as the original.
- [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 …
- 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.