Return To CS 110 Home

Colour Theme   Font Size Options
 
   
   
   
Pass By Value

CS110 Lab: C++ Function with Value-parameters

A variable declared in the heading of a function is called a parameter, also called a formal argument or a formal parameter. A variable or expression included in the call to a function is referred to as an argument, also known as an actual argument or actual parameter. Please read the following for further information:

Example


In the above example, the heading of printStars() function is void printStars(int numOfStars).

The parameter numOfStars is a value parameter because its data type int does not end with an ampersand ( & ). When it is called using the argument num_stars, i.e. printStars(num_stars);, then parameter numOfStars receives a copy of the value of num_stars.

While the function runs there are two copies of the data: one in the argument num_stars and one in the parameter numOfStars. If a statement inside the function printStars() were to change the value of numOfStars, this change would not affect the argument num_stars.