Explore BrainMass

Basics of Passing Arguments in C++

Use the program, Passing-by-Value, on Ex5_02 of the text and the program, Passing-by-Reference, on Ex5_07 as a starting point for this assignment.

Write a similar program, but change the code to pass two variables to the function call rather than one.

Answer the following questions after completing both programs:

- What is the purpose of the function header?
- How may you identify the body of a function?
- What does the return statement do?

Note. Do not combine these programs into one program.


Solution Preview

The attached program (main.cpp) shows how to pass two arguments to a
function both by reference and by value.

The function headers show the return type, the function name, and the
list of arguments that the function takes. For example:

int incr10byref(int& num1,int& num2)

This indicates that the function named "incr10byref" returns an
integer and takes to integer ...

Solution Summary

This solution shows how to pass arguments both by value and by reference in C++. It provides complete C++ program to illustrate this.