Contenido del Curso
C++ Data Types
2. Numerical Data Types
4. Other Data Types and Concepts
C++ Data Types
Type modifier
main.cpp
What those type modifiers do is change the size of a type. While int
takes up 4 bytes, short int
takes up 2 bytes, and the long int
8 bytes of memory.
Note
There is a shorter syntax available you can use any of them:
short
is equivalent toshort int
;long
is equivalent tolong int
;
So, we need to use long
(long int
) to store large values.
In contrast, we can use short
(short int
) to take up less memory. However, its range is narrower because of that. Here is the table with ranges that a type can hold:
Type | Size (bytes) | Range |
---|---|---|
short int | 2 | -32,768 to 32,767 |
int | 4 | -2,147,483,648 to 2,147,483,647 |
long int | 8 | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
Note
On Windows,
long
also takes up 4 bytes, just likeint
.
If you are working on Windows, you should uselong long int
(orlong long
) instead of justlong
.
Tarea
- Change the type of the variables so it can hold a larger number.
- Output the result of the expression.
¿Todo estuvo claro?
Contenido del Curso
C++ Data Types
2. Numerical Data Types
4. Other Data Types and Concepts
C++ Data Types
Type modifier
main.cpp
What those type modifiers do is change the size of a type. While int
takes up 4 bytes, short int
takes up 2 bytes, and the long int
8 bytes of memory.
Note
There is a shorter syntax available you can use any of them:
short
is equivalent toshort int
;long
is equivalent tolong int
;
So, we need to use long
(long int
) to store large values.
In contrast, we can use short
(short int
) to take up less memory. However, its range is narrower because of that. Here is the table with ranges that a type can hold:
Type | Size (bytes) | Range |
---|---|---|
short int | 2 | -32,768 to 32,767 |
int | 4 | -2,147,483,648 to 2,147,483,647 |
long int | 8 | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
Note
On Windows,
long
also takes up 4 bytes, just likeint
.
If you are working on Windows, you should uselong long int
(orlong long
) instead of justlong
.
Tarea
- Change the type of the variables so it can hold a larger number.
- Output the result of the expression.
¿Todo estuvo claro?