Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Unsigned | Other Data Types and Concepts
C++ Data Types
course content

Зміст курсу

C++ Data Types

C++ Data Types

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

book Unsigned

To represent a number in the binary system, it is necessary to store both its value and sign. One bit is dedicated to storing the sign, while the remaining bits are used to store the numerical value. The sign bit stores:

  • 0 if the number is non-negative;
  • 1 if the number is negative.

If we are certain that our variable can only hold non-negative numbers, we can utilize the unsigned type modifier. This modifier enables the storage of values without considering the sign.

Moreover, due to the increased memory available for storing the value, the range of possible values is wider; however, negative numbers are not included within this range. Therefore, the allowed ranges are as follows:

cpp

main

copy
12345678910
#include <iostream> int main() { unsigned int total_vehicles = 1446000000; unsigned short age = 21; std::cout << total_vehicles << std::endl; std::cout << age << std::endl; }

Note

Additionally, there is a signed type modifier available to indicate that a data type can accommodate both positive and negative numbers. But all numerical data types by default are signed, so there is no need to specify it explicitly.

Be sure to use unsigned only when the variable can not take negative numbers.
Assigning a negative value to an unsigned variable will not produce any errors, but the resulting value will be incorrect. Your task is to check this statement yourself!

Завдання

  • Assign the value -10 to the variable of any data type with an unsigned modifier.
  • Print this variable using the std::cout.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 5
toggle bottom row

book Unsigned

To represent a number in the binary system, it is necessary to store both its value and sign. One bit is dedicated to storing the sign, while the remaining bits are used to store the numerical value. The sign bit stores:

  • 0 if the number is non-negative;
  • 1 if the number is negative.

If we are certain that our variable can only hold non-negative numbers, we can utilize the unsigned type modifier. This modifier enables the storage of values without considering the sign.

Moreover, due to the increased memory available for storing the value, the range of possible values is wider; however, negative numbers are not included within this range. Therefore, the allowed ranges are as follows:

cpp

main

copy
12345678910
#include <iostream> int main() { unsigned int total_vehicles = 1446000000; unsigned short age = 21; std::cout << total_vehicles << std::endl; std::cout << age << std::endl; }

Note

Additionally, there is a signed type modifier available to indicate that a data type can accommodate both positive and negative numbers. But all numerical data types by default are signed, so there is no need to specify it explicitly.

Be sure to use unsigned only when the variable can not take negative numbers.
Assigning a negative value to an unsigned variable will not produce any errors, but the resulting value will be incorrect. Your task is to check this statement yourself!

Завдання

  • Assign the value -10 to the variable of any data type with an unsigned modifier.
  • Print this variable using the std::cout.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 5
toggle bottom row

book Unsigned

To represent a number in the binary system, it is necessary to store both its value and sign. One bit is dedicated to storing the sign, while the remaining bits are used to store the numerical value. The sign bit stores:

  • 0 if the number is non-negative;
  • 1 if the number is negative.

If we are certain that our variable can only hold non-negative numbers, we can utilize the unsigned type modifier. This modifier enables the storage of values without considering the sign.

Moreover, due to the increased memory available for storing the value, the range of possible values is wider; however, negative numbers are not included within this range. Therefore, the allowed ranges are as follows:

cpp

main

copy
12345678910
#include <iostream> int main() { unsigned int total_vehicles = 1446000000; unsigned short age = 21; std::cout << total_vehicles << std::endl; std::cout << age << std::endl; }

Note

Additionally, there is a signed type modifier available to indicate that a data type can accommodate both positive and negative numbers. But all numerical data types by default are signed, so there is no need to specify it explicitly.

Be sure to use unsigned only when the variable can not take negative numbers.
Assigning a negative value to an unsigned variable will not produce any errors, but the resulting value will be incorrect. Your task is to check this statement yourself!

Завдання

  • Assign the value -10 to the variable of any data type with an unsigned modifier.
  • Print this variable using the std::cout.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

To represent a number in the binary system, it is necessary to store both its value and sign. One bit is dedicated to storing the sign, while the remaining bits are used to store the numerical value. The sign bit stores:

  • 0 if the number is non-negative;
  • 1 if the number is negative.

If we are certain that our variable can only hold non-negative numbers, we can utilize the unsigned type modifier. This modifier enables the storage of values without considering the sign.

Moreover, due to the increased memory available for storing the value, the range of possible values is wider; however, negative numbers are not included within this range. Therefore, the allowed ranges are as follows:

cpp

main

copy
12345678910
#include <iostream> int main() { unsigned int total_vehicles = 1446000000; unsigned short age = 21; std::cout << total_vehicles << std::endl; std::cout << age << std::endl; }

Note

Additionally, there is a signed type modifier available to indicate that a data type can accommodate both positive and negative numbers. But all numerical data types by default are signed, so there is no need to specify it explicitly.

Be sure to use unsigned only when the variable can not take negative numbers.
Assigning a negative value to an unsigned variable will not produce any errors, but the resulting value will be incorrect. Your task is to check this statement yourself!

Завдання

  • Assign the value -10 to the variable of any data type with an unsigned modifier.
  • Print this variable using the std::cout.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 4. Розділ 5
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
some-alt