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

Sending a structure to a function - C Tutorial

From the course: C: Data Structures, Pointers, and File Systems

Start my 1-month free trial

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…

Contents