Course Content
C++ Data Types
3. Other Data Types and Type Conversion
C++ Data Types
Numerical Data Types Summary
In the preceding chapters, we covered the numerical data types int
, float
, and double
.
Additionally, we discussed type modifiers such as short
, long
, and unsigned
.
By combining these types and modifiers, we can select the most appropriate data type for our specific task.
However, it's important to note that in C++, the unsigned
and short
type modifiers cannot be used with floating-point types such as float
and double
.
With that being said, here is a table containing all the types:
Data Type | Size (bytes) | Range | Precision |
short | 2 | -32,768 to 32,767 | |
unsigned short | 2 | 0 to 65,535 | |
int | 4 | -2,147,483,648 to 2,147,483,647 | |
unsigned int | 4 | 0 to 4,294,967,295 | |
long ** | 8 | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | |
unsigned long ** | 8 | 0 to 18,446,744,073,709,551,615 | |
float | 4 | ±1.2e-38 to ±3.4e+38 | 7 digits |
double | 8 | ±2.2e-308 to ±1.8e+308 | 15 digits |
long double | 8 to 16* | Huge* | 15-33 digits* |
* means it depends on a system
** on Windows, long long
instead of long
Everything was clear?
Section 1. Chapter 9