From the course: C Essential Training
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Creating a function
- [Instructor] C offers no rules about when a function is necessary or required. It's best however, to add a function, when you use the same statements or perform the same process repeatedly in the code. For example, you could write a function to prompt for input that's prompted for several times. You could also build a function to handle a specific task. For example, a complex calculation, doing so can help make 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 a data type for the value returned, or you use void, if no value is returned. Then comes the function, name. Functions are named just like variables and the same rules apply. In the parentheses, you set arguments. Functions with no argument list void in the parentheses. A set of curly braces encloses the functions statements. Functions that have a return value must have a…
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 functions3m 21s
-
Creating a function3m 28s
-
Challenge: Writing a function46s
-
Solution: Writing a function1m 10s
-
Returning a value from a function2m 33s
-
Challenge: Returning a value42s
-
Solution: Returning a value1m 40s
-
Passing arguments to a function1m 52s
-
Challenge: Passing values44s
-
Solution: Passing values1m 22s
-
Using the main() function's arguments3m 30s
-
Retaining values in a function2m 58s
-
Creating recursive functions3m 53s
-
Challenge: Complete the code1m 14s
-
Solution: Complete the code1m 31s
-
-