Team 2550
Technical Documentation
|
|
A function (also known as a method, procedure, routine, subroutine, or subprogram) is a named block of code capable of taking inputs and outputting information. You have already used several functions.
In order to use predefined functions, you must:
You can also create your own functions. In order to do this, you need to:
Here is a very basic function.
Practice: Write a void function named printname that prints out your name. Call it from main 10 times using a loop.
If you want your function to return something, change void
to be a data type. A function can only return one value.
In order to get the return value, assign the value of a variable to it or provide it as an input to something else.
main()
must always return an int
. Unless otherwise specified, it will return 0, which signals the operating system that it exited successfully. If there are error conditions in your program that require it to exit early, you should return a nonzero value along with a message saying what is wrong.