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

Kursusindhold

C++ Intermediate | Mobile-Friendly

C++ Intermediate | Mobile-Friendly

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

book
Basics of Functions

The function is a block of statements that runs when it is called. The world of programming cannot exist without functions since they:

  • are reusable.

  • can test a particular part of your code.

  • can be applied to a number of cases if you change the parameters.

Let’s go deep into it. For instance, you have decided to program the cat. It should say "meow!":

python

Easy implementation. Repeating output will overload your code. However, what should we do if the cat must say meow twice or 20 times in different periods? In such a situation, we can use functions. To create a function, you need to specify the keyword void, the name of the function, followed by parentheses ():

python

Let's create the function sound() for the cat, which will print "meow!":

python
question mark

To create a function, you need to specify the keyword

Select the correct answer

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 4. Kapitel 1

Spørg AI

expand
ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

course content

Kursusindhold

C++ Intermediate | Mobile-Friendly

C++ Intermediate | Mobile-Friendly

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

book
Basics of Functions

The function is a block of statements that runs when it is called. The world of programming cannot exist without functions since they:

  • are reusable.

  • can test a particular part of your code.

  • can be applied to a number of cases if you change the parameters.

Let’s go deep into it. For instance, you have decided to program the cat. It should say "meow!":

python

Easy implementation. Repeating output will overload your code. However, what should we do if the cat must say meow twice or 20 times in different periods? In such a situation, we can use functions. To create a function, you need to specify the keyword void, the name of the function, followed by parentheses ():

python

Let's create the function sound() for the cat, which will print "meow!":

python
question mark

To create a function, you need to specify the keyword

Select the correct answer

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 4. Kapitel 1
Vi beklager, at noget gik galt. Hvad skete der?
some-alt