11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

84 Part II: Becoming a Functional C++ ProgrammerThe default argument type to a function is void, meaning that it takes noarguments. A function int fn(void) may be declared as int fn().The function construct made it possible for me to write two distinct parts ofthe FunctionDemo program separately. I concentrated on creating the sum ofa sequence of numbers when writing the sumSequence() function. I didn’tthink about other code that may call the function.Similarly, when writing main(), I concentrated on handling the summationreturned by sumSequence() while thinking only of what the function did —not how it worked.Understanding simple functionsThe simple function sumSequence() returns an integer value that it calculates.Functions may return any of the regular types of variables. For example,a function might return a double or a char (int, double, and char are afew of the variable types discussed in Chapter 2).If a function returns no value, the return type of the function is labeled void.A function may be labeled by its return type — for example, a function thatreturns an int is often known as an integer function. A function thatreturns no value is known as a void function.For example, the following void function performs an operation, but returnsno value:void echoSquare(){int value;cout > value;cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!