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

Conteúdo do Curso

Introduction to C++

Introduction to C++

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

Identifiers

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;

Clique ou arraste solte itens e preencha os espaços

Tudo estava claro?

Seção 2. Capítulo 2
We're sorry to hear that something went wrong. What happened?
some-alt