To access array elements by using a pointer, first initialize the pointer to the array. Each element in the array is accessed by adding its element number to the base address stored in the array. Elements in an array can be accessed by incrementing a pointer that references the array. Ensure when accessing array elements via a pointer that you don't reference elements beyond the last.
- [Instructor] It's often been said … that array notation is a shortcut for pointers … which isn't true. … You cannot fully substitute what a pointer does … by using array notation instead. … In this exercise file, text is a 10 element character array. … String input is fetched at line eight, … but see how the text variable lacks the address of operator? … That's because the compiler treats the array like a pointer. … It holds an address, the start of the array. … Let's build and run. … Type something short, hello. … Individual variables require the address of operator … when used with the scanf function. … Even an array element requires the ampersand … but not an array and not a pointer. … This exercise file displays the address … of the text array and the pointer assigned to that address. … Build and run. … And they're the same, but what about array elements? … In this exercise file, an integer array twos … contains five elements and pointer pt … is assigned that array's address at line nine. …
- 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.