Conteúdo do Curso
C++ Data Types
C++ Data Types
Specifying a Type
Being a typed language means that you must declare the type of a variable when you initialize it. To specify the data type for the variable you have to use the following syntax:
By specifying the variable's data type, we inform the computer about the amount of memory needed to store its value and how to interpret that value.
What actually happens when we create a variable of some type
Let's look at the example of an int
data type. As you will see in the next section, it requires 4 bytes (=32 bits) of data to hold its value. So, the computer must allocate 4 bytes of memory for storing this value.
The computer allocates 4 cells (bytes) of memory for the num
variable. When we assign the value to a num
, those cells will hold this value. Also, there is a memory address associated with the cells.
Values are stored in memory using a binary number system (sequence of 1s and 0s). So the numbers are being converted to a binary system first. The following video shows how the value of 1231
is stored in memory.
Note
Understanding how the numbers are being converted to the binary system is not required for this course. However, if you want to acquire that knowledge, you can check out our Numeral Systems course.
Obrigado pelo seu feedback!