Structures can have pointers as members and the entire structure can also be a pointer. Structure members that are pointer variables are accessed like any other structure member, effectively as a single variable. When a structure is declared as a pointer, the members are accessed by using the -> operator instead of the period, or dot, operator. When allocating memory for a structure pointer, ensure that you use the size of the structure to obtain the proper memory chunk in which to store the structure's data.
- [Instructor] Structures and pointers … dance together in two ways. … The first is to have a member of a structure … be a pointer, and the second is to have … the entire structure be a pointer. … In this code, the person structure … declared line seven has a pointer member, name. … Like any pointer variable, it holds the location … of an address in memory, in this instance, … to a character or string. … At line 16, storage space is allocated … for the name member of the you structure. … The number of bytes requested is equal … to the length of the string in buffer, … plus one for the null character. … The allocated address is saved in the name member … of the person structure variable you, at line 23. … The dot notation is the same … as for any other structure member. … As a pointer, name must be initialized, … or in this instance, memory assigned, … but the notation in the structure is the same, a dot. … Build and run. … And I'll type my name and lie about my age. … There you go, works. …
- 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.