From the course: Complete Guide to C Programming Foundations

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Working with structures and functions

Working with structures and functions - C Tutorial

From the course: Complete Guide to C Programming Foundations

Working with structures and functions

- [Instructor] Passing a structure member to a function works just like passing any variable. Here, the show color function accepts a single character argument and returns the corresponding color string. In the main function, pixel structure variable center is declared and its assigned values. Within the printf statement, two of the members are output directly. The third member is passed to the show color function and the return value is output as a string, which is the data type this function returns. The function call uses this format, the structure variable name .member, to pass the single character argument. The value is passed like any variable, but in the function, it's referenced by the data type and the local variable, the variable name used in the function, C. No dots are required here as it's the value that's passed, not the structure member construction, and you see the output here. You can also pass an entire structure to a function shown here in the show pixel function…

Contents