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

Creating a function - C Tutorial

From the course: C Essential Training

Start my 1-month free trial

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…

Contents