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

Course Content

C++ Data Types

C++ Data Types

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

bookUsing Integers

In the previous chapter, we found out that assigning a value exceeding the -2,147,483,648 to 2,147,483,647 range would not raise any error. Instead it will cause an overflow.

Remember

Overflow occurs when a calculation produces a result that is too large to be represented by the data type used.

For example, if you try to store a value larger than the maximum representable value for an integer type, an overflow will occur, and the result will wrap around or be truncated, leading to unexpected behavior in your program.

It can lead to critical bugs in your programs, so that's something to keep in mind.We will learn how to handle numbers that are too large in the next chapter.

For now, let's practice!

Task

  • Fix the expression so it no longer causes an overflow.
  • Change the order of operations, at first divide each number by 2 and only then add them.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 2
toggle bottom row

bookUsing Integers

In the previous chapter, we found out that assigning a value exceeding the -2,147,483,648 to 2,147,483,647 range would not raise any error. Instead it will cause an overflow.

Remember

Overflow occurs when a calculation produces a result that is too large to be represented by the data type used.

For example, if you try to store a value larger than the maximum representable value for an integer type, an overflow will occur, and the result will wrap around or be truncated, leading to unexpected behavior in your program.

It can lead to critical bugs in your programs, so that's something to keep in mind.We will learn how to handle numbers that are too large in the next chapter.

For now, let's practice!

Task

  • Fix the expression so it no longer causes an overflow.
  • Change the order of operations, at first divide each number by 2 and only then add them.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 2
toggle bottom row

bookUsing Integers

In the previous chapter, we found out that assigning a value exceeding the -2,147,483,648 to 2,147,483,647 range would not raise any error. Instead it will cause an overflow.

Remember

Overflow occurs when a calculation produces a result that is too large to be represented by the data type used.

For example, if you try to store a value larger than the maximum representable value for an integer type, an overflow will occur, and the result will wrap around or be truncated, leading to unexpected behavior in your program.

It can lead to critical bugs in your programs, so that's something to keep in mind.We will learn how to handle numbers that are too large in the next chapter.

For now, let's practice!

Task

  • Fix the expression so it no longer causes an overflow.
  • Change the order of operations, at first divide each number by 2 and only then add them.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

In the previous chapter, we found out that assigning a value exceeding the -2,147,483,648 to 2,147,483,647 range would not raise any error. Instead it will cause an overflow.

Remember

Overflow occurs when a calculation produces a result that is too large to be represented by the data type used.

For example, if you try to store a value larger than the maximum representable value for an integer type, an overflow will occur, and the result will wrap around or be truncated, leading to unexpected behavior in your program.

It can lead to critical bugs in your programs, so that's something to keep in mind.We will learn how to handle numbers that are too large in the next chapter.

For now, let's practice!

Task

  • Fix the expression so it no longer causes an overflow.
  • Change the order of operations, at first divide each number by 2 and only then add them.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 2. Chapter 2
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt