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

Contenido del Curso

Introduction to C++

Introduction to C++

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

bookTypes of Variables

In the previous chapters, we printed some expressions. However, what to do if we need to store these expressions for future usage? In C++ (like in other programming languages) there are containers to keep data - variables. For each type of data (numbers, strings, characters) there is a type of variable.

Let’s take a look at the most often used types:

Why do we need to know the type of each variable? In Python, for example, you can store the data without worrying about its type.

When you declare variables in C++, the type of variable is a mandatory parameter, so knowing and correctly using data types will help to avoid many mistakes.

Let's look at an example of a variable declaration:

12
int num = 42; cout << num;
copy

You can also reassign your variable if it’s needed:

123
double num = 3.2; num = 12.44; cout << num;
copy

You might also declare a variable but assign the value later or define the multiple variables of the same type in one declaration:

Tarea
test

Swipe to show code editor

Practice:

  1. Declare the variable x type of string.
  2. Assign the value "Hello" to the variable x ( don’t forget about double quotes).
  3. Reassign x to the "Bye".
  4. Print the variable x after these operations.

Don’t forget about semicolon ; at the end of lines.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 1
toggle bottom row

bookTypes of Variables

In the previous chapters, we printed some expressions. However, what to do if we need to store these expressions for future usage? In C++ (like in other programming languages) there are containers to keep data - variables. For each type of data (numbers, strings, characters) there is a type of variable.

Let’s take a look at the most often used types:

Why do we need to know the type of each variable? In Python, for example, you can store the data without worrying about its type.

When you declare variables in C++, the type of variable is a mandatory parameter, so knowing and correctly using data types will help to avoid many mistakes.

Let's look at an example of a variable declaration:

12
int num = 42; cout << num;
copy

You can also reassign your variable if it’s needed:

123
double num = 3.2; num = 12.44; cout << num;
copy

You might also declare a variable but assign the value later or define the multiple variables of the same type in one declaration:

Tarea
test

Swipe to show code editor

Practice:

  1. Declare the variable x type of string.
  2. Assign the value "Hello" to the variable x ( don’t forget about double quotes).
  3. Reassign x to the "Bye".
  4. Print the variable x after these operations.

Don’t forget about semicolon ; at the end of lines.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 1
toggle bottom row

bookTypes of Variables

In the previous chapters, we printed some expressions. However, what to do if we need to store these expressions for future usage? In C++ (like in other programming languages) there are containers to keep data - variables. For each type of data (numbers, strings, characters) there is a type of variable.

Let’s take a look at the most often used types:

Why do we need to know the type of each variable? In Python, for example, you can store the data without worrying about its type.

When you declare variables in C++, the type of variable is a mandatory parameter, so knowing and correctly using data types will help to avoid many mistakes.

Let's look at an example of a variable declaration:

12
int num = 42; cout << num;
copy

You can also reassign your variable if it’s needed:

123
double num = 3.2; num = 12.44; cout << num;
copy

You might also declare a variable but assign the value later or define the multiple variables of the same type in one declaration:

Tarea
test

Swipe to show code editor

Practice:

  1. Declare the variable x type of string.
  2. Assign the value "Hello" to the variable x ( don’t forget about double quotes).
  3. Reassign x to the "Bye".
  4. Print the variable x after these operations.

Don’t forget about semicolon ; at the end of lines.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

In the previous chapters, we printed some expressions. However, what to do if we need to store these expressions for future usage? In C++ (like in other programming languages) there are containers to keep data - variables. For each type of data (numbers, strings, characters) there is a type of variable.

Let’s take a look at the most often used types:

Why do we need to know the type of each variable? In Python, for example, you can store the data without worrying about its type.

When you declare variables in C++, the type of variable is a mandatory parameter, so knowing and correctly using data types will help to avoid many mistakes.

Let's look at an example of a variable declaration:

12
int num = 42; cout << num;
copy

You can also reassign your variable if it’s needed:

123
double num = 3.2; num = 12.44; cout << num;
copy

You might also declare a variable but assign the value later or define the multiple variables of the same type in one declaration:

Tarea
test

Swipe to show code editor

Practice:

  1. Declare the variable x type of string.
  2. Assign the value "Hello" to the variable x ( don’t forget about double quotes).
  3. Reassign x to the "Bye".
  4. Print the variable x after these operations.

Don’t forget about semicolon ; at the end of lines.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 2. Capítulo 1
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt