Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Type modifier | Numerical Data Types
C++ Data Types
course content

Conteúdo do Curso

C++ Data Types

C++ Data Types

1. Introduction
2. Numerical Data Types
3. Text Data Type
4. Other Data Types and Concepts

bookType modifier

short and long are the type modifiers.

cpp

main

copy
12345678910
#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 to short int;
  • long is equivalent to long 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 like int.

If you are working on Windows, you should use long long int (or long long) instead of just long.

Tarefa

  • Change the type of the variables so it can hold a larger number.
  • Output the result of the expression.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 3
toggle bottom row

bookType modifier

short and long are the type modifiers.

cpp

main

copy
12345678910
#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 to short int;
  • long is equivalent to long 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 like int.

If you are working on Windows, you should use long long int (or long long) instead of just long.

Tarefa

  • Change the type of the variables so it can hold a larger number.
  • Output the result of the expression.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 3
toggle bottom row

bookType modifier

short and long are the type modifiers.

cpp

main

copy
12345678910
#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 to short int;
  • long is equivalent to long 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 like int.

If you are working on Windows, you should use long long int (or long long) instead of just long.

Tarefa

  • Change the type of the variables so it can hold a larger number.
  • Output the result of the expression.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

short and long are the type modifiers.

cpp

main

copy
12345678910
#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 to short int;
  • long is equivalent to long 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 like int.

If you are working on Windows, you should use long long int (or long long) instead of just long.

Tarefa

  • Change the type of the variables so it can hold a larger number.
  • Output the result of the expression.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Seção 2. Capítulo 3
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
some-alt