course content

Course Content

Introduction to C++

Data TypesData Types

When declaring a variable, you need to specify what kind of data we will store in it, or rather, "what type". C++ has a large number of data types for easy memory handling. The most common is int, double, bool, and char, other data types come from them.

The int data type corresponds to positive and negative integers.

The data type double corresponds to positive and negative non-integer numbers.

cpp

main.cpp

The bool data type corresponds to 2 boolean values: 0 (false) and 1 (true). Usually, they describe the state of the «button».

  • Light on = true = 1;
  • Light off = false = 0.

The char data type stores a single character value:

cpp

main.cpp

The data type tells the compiler how much memory you need to store your data. If the number that you are going to store in the variable is larger than the type of the variable allows, then an overflow will occur.

cpp

main.cpp

When we run this program, we will see that, for some reason, our variable has become equal to -2147483648...:

question-icon

Choose correct type for variable:

Select the correct answer

Section 2.

Chapter 2