C++ functions can be declared inline

If they contain just simple lines of code, use no for loops or the like, C++ functions can be declared inline. This means their code will be inserted right everywhere the function is used. That's somehow like a macro. Main advantage is the program will be faster. A little drawback is it will be bigger, because the full code of the function was inserted everywhere it is used: 

#include <iostream.h>
#include <math.h>

inline double hypothenuse (double a, double b)
return sqrt (a * a + b * b);

void main ()
double k = 6, m = 9;

// Next two lines produce exactly the same code:

cout << hypothenuse (k, m) << endl;
cout << sqrt (k * k + m * m) << endl;

Added on May 24, 2007 Comment