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. |
Home Function Functions with Multiple Parameters | ||
See also: Functions with Results, Stack Diagrams for Recursive Functions | ||
Functions with Multiple Parameters
cout << hour; cout << ":"; cout << minute; } It might be tempting to write (int hour, minute), but that format is only legal for variable declarations, not for parameters. Another common source of confusion is that you do not have to declare the types of arguments. The following is wrong! int hour = 11;int minute = 59; printTime (int hour, int minute); // WRONG! In this case, the compiler can tell the type of hour and minute by looking at their declarations. It is unnecessary and illegal to include the type when you pass them as arguments. The correct syntax is printTime (hour, minute).
|
||
Home Function Functions with Multiple Parameters |