7.1 — Function parameters and arguments

In Chapter 1, we covered function basics in the following sections:

You should be familiar with the concepts discussed in those lessons before proceeding.

Parameters vs Arguments

Up until now, we have not differentiated between function parameters and arguments. In common usage, the terms parameter and argument are often interchanged. However, for the purposes of further discussion, we will make a distinction between the two:

A function parameter is a variable declared in the prototype or declaration of a function:

An argument is the value that is passed to the function in place of a parameter:

When a function is called, all of the parameters of the function are created as variables, and the value of the arguments are copied into the parameters. For example:

When foo() is called with arguments 6 and 7, foo’s parameter x is created and assigned the value of 6, and foo’s parameter y is created and assigned the value of 7.

Even though parameters are not declared inside the function block, function parameters have local scope. This means that they are created when the function is invoked, and are destroyed when the function block terminates:

There are 3 primary methods of passing arguments to functions: pass by value, pass by reference, and pass by address. The following sections will address each of those cases individually.

7.2 -- Passing arguments by value
6.15 -- An introduction to std::array

18 comments to 7.1 — Function parameters and arguments

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">