Contenido del Curso
C++ Data Types
C++ Data Types
Type modifier
short
and long
are the type modifiers.
main
#include <iostream> int main() { long int large_number = 4000000000; short int small_number = 45; std::cout << "Large number: " << large_number << std::endl; std::cout << "Small number: " << small_number <<std:: endl; }
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:
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.
¡Gracias por tus comentarios!
Type modifier
short
and long
are the type modifiers.
main
#include <iostream> int main() { long int large_number = 4000000000; short int small_number = 45; std::cout << "Large number: " << large_number << std::endl; std::cout << "Small number: " << small_number <<std:: endl; }
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:
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.
¡Gracias por tus comentarios!
Type modifier
short
and long
are the type modifiers.
main
#include <iostream> int main() { long int large_number = 4000000000; short int small_number = 45; std::cout << "Large number: " << large_number << std::endl; std::cout << "Small number: " << small_number <<std:: endl; }
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:
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.
¡Gracias por tus comentarios!
short
and long
are the type modifiers.
main
#include <iostream> int main() { long int large_number = 4000000000; short int small_number = 45; std::cout << "Large number: " << large_number << std::endl; std::cout << "Small number: " << small_number <<std:: endl; }
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:
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.