To pass a structure variable to a function, the structure definition must be defined externally, outside of all functions in the source code file. Further, the structure definition must come before any function prototypes that reference the structure. Otherwise, passing a structure to a function works like passing any individual data type.
- [Instructor] Passing a structure member to a function … works just like passing any variable. … Though the member is referenced as such, … only in the calling function. … In this code at line twenty, the color member … of the center structure variable is passed … to the show_color function. … In the function itself at line twenty six, … it requires only a character variable as an argument. … And the color member of the center structure … is a single character variable as defined up at line ten, … so all of this works. … Within the main function, the structure member reference … is used, and there it is at line twenty; center.color. … But in the show_color function, it appears as argument c, … and that's how it's expressed throughout that function. … Build and run. … You can also pass an entire structure to a function, … as this code hints at. … The show_pixel function at line twenty two … receives a pixel structure variable as its argument. … Up at line seventeen, you see that … the structure variable name is passed, it's sent off …
- 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.