Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Constant | Variables
Introduction to C++ | Mobile-Friendly

book
Constant

If you have a static variable that never changes and you want that nobody overrides your variable, use the const keyword by declaration. It makes the variable unchangable (constsant).

For example:

python
const double x = 42;

The variable x will always be 42 and nobody can change it. The following code would cause an error:

python
const int x = 10;
x = 15;

You should declare variables as constants if you are sure that they will probably never change:

python
const int monthPerYear = 12;
const char firstAlphabetLetter = 'A';
question-icon

Define the variable secondsPerMinute as the const variable:

_ _ _
_ _ _
_ _ _
_ _ _
_ _ _
;

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

dots
constant
dots
char
dots
int
dots
secondsPerMinute
dots
=
dots
60
dots
const
dots
==

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 8

Chieda ad AI

expand
ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

We use cookies to make your experience better!
some-alt