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

Course Content

Introduction to C++

Introduction to C++

1. Basics
2. Variables
3. Conditional Statements
4. Loops
5. Intro to Arrays

bookIdentifiers

Each variable has its unique name - identifier. There’re 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.

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

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 2
some-alt