Zebra0.com

cppFinding half the value

Finding half the value

Instead of passing the values of variables to functions, we can pass the variable itself (its address) to a function. This is called "pass by reference".

In this example we use a function to give a variable a new value that is half its original value. Obviously, we could just say num=num/2; but this function illustrates pass by reference without getting too complicated.