Using Functions


You know how to pass parameters, you know how to return values -- what's left?

Nothing! You're ready to use it!

Calling functions in C++ is exactly the same as with Pascal, with one key difference -- if you're not passing any variables to a function when you're calling it, you still need to use the parentheses. Here's an example :

int taco, warehouse;

warehouse = Get_Warehouse();
taco = Get_Number_of_Tacos(warehouse);
cout << "I found " << taco << " tacos in the warehouse. Yum!\n";

The above example starts by declaring two integers, taco and warehouse. The fictional function Get_Warehouse is then called, and its return value is assigned to warehouse. On the next line, Get_Number_of_Tacos with warehouse as its argument. It's return value is placed in taco, which is then printed out.

Mmm..Tacos


Table of Contents

Procedures/Functions | Returning Values | Passing Variables | Using Functions
Function Overloading | Default Parameters | Exercises