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

book
Identifiers

Each variable has its unique name - identifier. There are some rules for naming variables:

  • Names must start with a letter or underscore _ and contain only letters, digits, and underscores (no special characters or whitespaces).

  • Names can be different because of the case (myDog and MyDog are two different variables).

  • Reserved words such as int cannot be identifiers.

There are short names for variables such as x and y, and also descriptive names like monthIncome or amountPerYear. The good rule is to use descriptive names since it makes your code more clear and understandable.

In cases, you don’t want to define the type of the variable automatically by declaration you can use the auto keyword. It infers the type from the value of the variable, so it’s necessary to initialize the variable when you define it.

python
auto x = 5; // int
auto y = "Hello"; // string
question-icon

Define the variable automatically using the valid name of the variable:

_ _ _
_ _ _
= 42;

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

dots
string
dots
scorePlayer#1
dots
auto
dots
char
dots
scorePlayer1

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 2

Fragen Sie AI

expand
ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

some-alt