Arguments and Function Scope
This lesson deals with the nature of the arguments being passed to a function.
We'll cover the following
In the previous lesson, we learned how to pass arguments into a function. It is a very simple process, but there are a few things we need to know about how the C++ compiler treats these arguments.
Pass-by-Value
The compiler never actually sends the variables into the function. Instead, a copy of each argument is made and used in the scope of the function. This concept is known as passing-by-value. Only the values of the arguments are passed into the functions, not the arguments themselves.
When the function ends, all the argument copies and the variables created inside the function are destroyed forever. Basically, changing the value of an argument inside a function won’t change it outside the function.
Have a look at the function below, which multiplies its argument by 10:
Get hands-on with 1400+ tech skills courses.