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.
Creating a function - C Tutorial
From the course: Complete Guide to C Programming Foundations
Creating a function
- [Instructor] C offers no rules regarding when functions are necessary or required. It's best, however, to write a function when you use the same statements or perform the same process repeatedly in the code, for example, write a function for an input prompt used several times. You can also build a function to handle a specific task, for example, a complex calculation. Doing so makes your code more readable. And you can write a function whenever the mood hits you. Again, there are no rules. When you code a function, you set its data type for the value returned, or you use void when no value is returned. Then comes the function name. Use the same rules for naming variables as for naming functions. In parentheses, you set a list of arguments. Functions with no arguments list void in the parentheses. A set of curly braces encloses the functions statements. Even when the function has only one statement, enclose it in braces. Functions that return a value must have a return statement to…
Contents
-
-
-
-
-
-
-
Understanding functions3m 11s
-
(Locked)
Creating a function4m 52s
-
(Locked)
Challenge: Writing a function39s
-
(Locked)
Solution: Writing a function1m 49s
-
(Locked)
Returning a value from a function2m 23s
-
(Locked)
Challenge: Returning a value53s
-
(Locked)
Solution: Returning a value2m
-
(Locked)
Passing arguments to a function2m 22s
-
(Locked)
Challenge: Passing values41s
-
(Locked)
Solution: Passing values1m 50s
-
(Locked)
Using the main() function's arguments2m 13s
-
(Locked)
Retaining values in a function2m 34s
-
(Locked)
Creating recursive functions3m 44s
-
(Locked)
Chapter challenge: Write the functions1m 14s
-
(Locked)
Chapter solution: Write the functions2m 15s
-
-
-
-
-
-
-