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

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