The C++Course provides a general introduction to programming in C++. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details.


Functions

In the last section I mentioned "all the things functions are good for." About this time, you might be wondering what exactly those things are. Here are some of the reasons functions are useful:

  • By giving a name to a sequence of statements, you make your program easier to read and debug.
  • Dividing a long program into functions allows you to separate parts of the program, debug them in isolation, and then compose them into a whole.
  • Functions facilitate both recursion and iteration.
  • Well-designed functions are often useful for many programs. Once you write and debug one, you can reuse it.


Last Update: 2005-11-21