Passing Parameters

This lesson discusses the ways values are passed through functions, the methods used and the scope of variables declared.

We'll cover the following

Passing Methods

Values can be passed to a function through two methods.

By default, values are passed to a function through a method called:

  • pass by value.

This means that:

  • value of the variable is passed, not the variable itself.

This would be like giving a person a copy of your driver’s license. They can read all of your information, ​and they can change whatever they want on their copy, but the original is not altered in any way.

If desired, a value can be passed through the other method called:

  • pass by reference

This means that:

  • Function is actually given the address of the variable, allowing it direct access to the information.
  • Placing a & after the data type in the function definition allows direct access (this must also be present in any forward declaration).

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy