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 - 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
-
-
-
-
-
-
-
-
Understanding arrays2m 48s
-
(Locked)
Working with arrays2m 51s
-
(Locked)
Challenge: Creating an array55s
-
(Locked)
Solution: Creating an array1m 41s
-
(Locked)
Passing an array to a function2m 45s
-
(Locked)
Working with multi-dimensional arrays2m 42s
-
(Locked)
Building a structure3m 31s
-
(Locked)
Nesting structures3m 17s
-
(Locked)
Challenge: Constructing a structure1m 3s
-
(Locked)
Solution: Constructing a structure3m 5s
-
(Locked)
Putting structures into an array2m 37s
-
(Locked)
Working with structures and functions3m 47s
-
(Locked)
Chapter challenge: Manipulating a structure1m 22s
-
(Locked)
Chapter solution: Manipulating a structure2m 4s
-
-
-
-
-
-