From the course: C: Data Structures, Pointers, and File Systems
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Sending a structure to a function - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
Sending a structure to a function
- [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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Understanding arrays2m 59s
-
Working with arrays3m 5s
-
Modifying arrays3m 11s
-
Passing an array to a function3m 17s
-
Working multi-dimensional arrays3m 2s
-
Building a structure3m 23s
-
Nesting structures2m 56s
-
Creating an array of structures2m 28s
-
Sending a structure to a function3m 36s
-
Understanding a union2m 47s
-
Challenge: Presidents of the U.S.A.1m 38s
-
Solution: Presidents of the U.S.A.2m 52s
-
-
-
-
-
-