FAQ 2.03 What are the basics of functions?

graphics/new_icon.gif

Functions are one of the important ways to decompose software into smaller, manageable chunks. Functions can have return values (for example, a function that computed a value might return that value), or they can return nothing. If they return nothing, the return type is stated as void and the function is sometimes called a procedure.

In the following example, function f() takes no parameters and returns nothing (that is, its return type is void), and function g() takes two parameters of type int and returns a value of type float.

 void f() {   // ... } float g(int x, int y) {   float sum = x + y;   float avg = sum / 2.0;   return avg; } int main() {   f();   float z = g(2, 3); } 


C++ FAQs
C Programming FAQs: Frequently Asked Questions
ISBN: 0201845199
EAN: 2147483647
Year: 2005
Pages: 566
Authors: Steve Summit

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net