Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Parameters | Functions
C++ Intermediate | Mobile-Friendly
course content

Cursusinhoud

C++ Intermediate | Mobile-Friendly

C++ Intermediate | Mobile-Friendly

1. Data Types and Arrays
2. References & Pointers
3. Dynamic Memory
4. Functions

book
Parameters

Let’s imagine we have 3 pets: dog, cat, and pig. They all make different sounds, and it would be silly to write 3 different functions with the same functionality (outputting words). Here we can use parameters! Parameters (or arguments) act like variables inside the function and are specified with their type inside the parentheses after the function. You can use as many arguments as you want:

Code:

12345678910111213
// Function declaration void myFunc(string animal, string sound) { &nbsp; cout << animal << " says " << sound << endl; } int main() { &nbsp;&nbsp;&nbsp;&nbsp; // Call the function to be executed &nbsp;&nbsp;&nbsp;&nbsp; myFunc("cat", "meow"); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myFunc("dog", "bow"); &nbsp;&nbsp;&nbsp;&nbsp; myFunc("pig", "wee"); &nbsp;&nbsp;&nbsp;&nbsp; return 0; }
copy

Variables you use can be any type, and your function can also accept different types simultaneously!

question-icon

Create the function which output the name and the age of the person:

#include <iostream>
using namespace std;

myFunc(name,age){
     cout << name << " is " << age << " years old." << endl;
}

int main(){
    myFunc(
,2);
    myFunc("Fiona",
);
}
Liam is 2 years old.
Fiona is 20 years old.

Click or drag`n`drop items and fill in the blanks

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 4. Hoofdstuk 3

Vraag AI

expand
ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

course content

Cursusinhoud

C++ Intermediate | Mobile-Friendly

C++ Intermediate | Mobile-Friendly

1. Data Types and Arrays
2. References & Pointers
3. Dynamic Memory
4. Functions

book
Parameters

Let’s imagine we have 3 pets: dog, cat, and pig. They all make different sounds, and it would be silly to write 3 different functions with the same functionality (outputting words). Here we can use parameters! Parameters (or arguments) act like variables inside the function and are specified with their type inside the parentheses after the function. You can use as many arguments as you want:

Code:

12345678910111213
// Function declaration void myFunc(string animal, string sound) { &nbsp; cout << animal << " says " << sound << endl; } int main() { &nbsp;&nbsp;&nbsp;&nbsp; // Call the function to be executed &nbsp;&nbsp;&nbsp;&nbsp; myFunc("cat", "meow"); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myFunc("dog", "bow"); &nbsp;&nbsp;&nbsp;&nbsp; myFunc("pig", "wee"); &nbsp;&nbsp;&nbsp;&nbsp; return 0; }
copy

Variables you use can be any type, and your function can also accept different types simultaneously!

question-icon

Create the function which output the name and the age of the person:

#include <iostream>
using namespace std;

myFunc(name,age){
     cout << name << " is " << age << " years old." << endl;
}

int main(){
    myFunc(
,2);
    myFunc("Fiona",
);
}
Liam is 2 years old.
Fiona is 20 years old.

Click or drag`n`drop items and fill in the blanks

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 4. Hoofdstuk 3
Onze excuses dat er iets mis is gegaan. Wat is er gebeurd?
some-alt