C++ Book


Summary

In this chapter, you should have learned the following concepts:

  • Functions allow you to break up your programs into manageable chunks.
  • One way to declare a function is to write a function prototype—code that lists the return value, name, and parameter types of a function.
  • Defining a function means writing all the code that makes the function tick.
  • You can use the ‘return’ statement to return a value from a function. You can also use ‘return’ to end a function that has ‘void’ as its return type.
  • A variable’s scope determines where the variable can be seen in your program.
  • Global variables are accessible from any part of your program. In general, you should try to limit your use of global variables.
  • Global constants are accessible from any part of your program. Using global constants can make your program code clearer.
  • Default arguments are assigned to a parameter if no value for the parameter is specified in the function call.
  • Function overloading is the process of creating multiple definitions for the same function, each of which has a different set of parameters.
  • Function inlining is the process of asking the compiler to inline a function—meaning that the compiler should make a copy of the function everywhere in the code where the function is called. Inlining very small functions can sometimes yield a performance boost.