Concept
How do C functions return values to the calling function?
ComputerScienceOne / Void Functions
"18.1. Defining & Using Functions\n\ndouble getDistance(double x1, double y1, double x2, double y2) {\n\ndouble xDiff = (x1-x2);\n\ndouble yDiff = (y1-y2);\n\nreturn sqrt( xDiff * xDiff + yDiff * yDiff);\n\n}\n\ndouble getMonthlyPayment(double principle, double apr, int terms) {\n\ndouble rate = (apr / 12.0);\n\ndouble payment = (principle * rate) / (1-pow(1+rate, -terms));\n\nreturn payment;\n\n}\n\nThe keyword return is used to specify the value that is returned to the calling function."
Related Ideas
- How do you call a function in C?ComputerScienceOne · Calling Functions
- How is a C function prototype turned into a function definition?ComputerScienceOne · Declaration: Prototypes
- How do functions work in programming languages?ComputerScienceOne · Functions
- What information does a C function prototype specify?ComputerScienceOne · Declaration: Prototypes
- How do you call functions in C?ComputerScienceOne · Organizing Functions
- How do you use the C standard mathematics library?ComputerScienceOne · Preprocessor Directives
- How can pointers be used to pass variables by reference?ComputerScienceOne · Passing By Reference
- How can pass-by-reference parameters return both roots of a quadratic equation?ComputerScienceOne · Quadratic Roots