bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/C++/C++ Functions
C++•C++ Functions

C++ Function Parameters

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind C++ Function Parameters?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___
3Order

Put the learning moves in the order that makes the concept easiest to apply.

Parameters are specified after the function name, inside the parentheses.
Information can be passed to functions as a parameter.
Parameters and Arguments

Parameters and Arguments

Information can be passed to functions as a parameter. Parameters act as variables inside the function.

Parameters are specified after the function name, inside the parentheses. You can add as many parameters as you want, just separate them with a comma:

Syntax

void
functionName
( parameter1 , parameter2 , parameter3 ) {
 // code to be executed
}

The following example has a function that takes a string called fname as parameter. When the function is called, we pass along a first name, which is used inside the function to print the full name:

Example

void myFunction( string fname ) {
  cout << fname << " Refsnes\n";
}
int main() {
  myFunction( "Liam" );
  myFunction( "Jenny" );
  myFunction( "Anja" );
  return 0;
}
// Liam Refsnes // Jenny Refsnes // Anja Refsnes

When a parameter is passed to the function, it is called an argument . So, from the example above: fname is a parameter , while Liam , Jenny and Anja are arguments .

Previous

C++ Functions

Next

C++ Default Parameters