Ed has created and taught college courses since 2002 and has a Doctorate of Computer Science and three MS degrees. He has authored several tech books.
Numeric Data Types in C++ Programming
C++ Numeric Data Types
C++ is a core programming language that makes great use of numeric data types. These numeric data types can be categorized as integers (whole numbers) and floating points (which have decimal points). Let's look at each category of numeric data types.

An error occurred trying to load this video.
Try refreshing the page, or contact customer support.
You must cCreate an account to continue watching
Register to view this lesson
As a member, you'll also get unlimited access to over 88,000 lessons in math, English, science, history, and more. Plus, get practice tests, quizzes, and personalized coaching to help you succeed.
Get unlimited access to over 88,000 lessons.
Try it nowAlready registered? Log in here for access
BackResources created by teachers for teachers
I would definitely recommend Study.com to my colleagues. It’s like a teacher waved a magic wand and did the work for me. I feel like it’s a lifeline.
You're on a roll. Keep up the good work!
Just checking in. Are you still watching?
Yes! Keep playing.Integers
Integers, referred to in code as int, come in several forms. A short int can be any number in the range of -32,768 to 32,767. A regular int, or just int, has a much larger range of -2,147,483,648 to 2,147,483,647.
A long int, referred to as long or double, has a range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
It's important to realize that there is no single standard for numeric data types in C++ and the names and range values can be slightly different depending on the implementation and processor. What is provided in this lesson are the prevailing ranges.
We can execute the following lines of code to determine the range of each data type.
cout << 'short int Min/Max : ' << SHRT_MIN << ' / ' << SHRT_MAX << endl;
cout << 'int Min/Max : ' << INT_MIN << ' / ' << INT_MAX << endl;
cout << 'long Min/Max : ' << LONG_MIN << ' / ' << LONG_MAX << endl;
The output is as follows:
short int Min/Max : -32768 / 32767
int Min/Max : -2147483648 / 2147483647
long Min/Max : -9223372036854775808 / 9223372036854775807
Integers can also be signed (support for negative numbers) or unsigned. We can use the following code to determine the maximum value of unsigned integers:
cout << 'unsigned short int Max : ' << USHRT_MAX << endl;
cout << 'unsigned int Max : ' << UINT_MAX << endl;
cout << 'unsigned long Max : '<< ULONG_MAX << endl;
The output of this code is as follows:
unsigned short int Max : 65535
unsigned int Max : 4294967295
unsigned long Max : 18446744073709551615
Floating Points
Floating points can have a decimal, which provide a greater level of precision over integers.
There are three types of floating point numbers in C++: float (the smallest), double (twice the size of floats), and long double (twice the size of doubles). The following code will generate output to display the minimum and maximum value of the float data types.
cout << '\tFloat \t\t' << 'Double \t\t' << 'Long Double' << endl;
cout << 'Min : ' << FLT_MIN << '\t' << DBL_MIN << '\t' << LDBL_MIN << endl;
cout << 'Max : ' << FLT_MAX << '\t' << DBL_MAX << '\t' << LDBL_MAX << endl;
The output for the preceding code is provided here:
Float Double Long Double
Min : 1.17549e-38 2.22507e-308 3.3621e-4932
Max : 3.40282e+38 1.79769e+308 1.18973e+4932
Memory Allocation
Numeric data types, like other data types, require memory allocation whenever a variable is defined. How much memory is allocated depends on the data type. A good programming practice is to use the smallest data type possible for any given situation to conserve memory.
The following C++ code uses the sizeof() operator to determine how many bytes each of the numeric data types require.
cout << ' NUMERIC SIZE TABLE' << endl;
cout << '=======================' << endl;
cout << '| Data Type | Bytes |' << endl;
cout << '=======================' << endl;
cout << '| short int | ' << sizeof(short int) << ' |' << endl;
cout << '| int | ' << sizeof(int) << ' |' << endl;
cout << '| float | ' << sizeof(float) << ' |' << endl;
cout << '| double | ' << sizeof(double) << ' |' << endl;
cout << '| long | ' << sizeof(long) << ' |' << endl;
cout << '| unsigned long | ' << sizeof(unsigned long) << ' |' << endl;
cout << '| long double | ' << sizeof(long double) << ' |' << endl;;
cout << '=======================' << endl;
Examining the output in this table reveals the number of bytes required by each numeric data type.
NUMERIC SIZE TABLE
=======================
Data Type Bytes
=======================
short int 2 int 4 float 4 double 8 long 8 unsigned long 8 long double 16
=======================
Lesson Summary
There are two primary categories of numbers in the C++ programming language. Integers are whole numbers can be:
- A short int: range of -32,768 to 32,767
- A regular int: range of -2,147,483,648 to 2,147,483,647
- A long int: range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Integers can also be signed or unsigned, with signed numbers supporting negative numbers. The other category of numbers in C++ are floating points, which support decimal places. There are three types of floating point numbers in C++:
- Float, the smallest
- Double, twice the size of floats
- Long double, twice the size of doubles
All numeric data types require memory to be allocated when a variable is defined. The sizeof() operator can be used to determine how many bytes each of the numeric data types require. For example, a long int requires eight bytes of memory, while a short int requires two bytes.
To unlock this lesson you must be a Study.com Member.
Create your account
Register to view this lesson
Unlock Your Education
See for yourself why 30 million people use Study.com
Become a Study.com member and start learning now.
Become a MemberAlready a member? Log In
BackResources created by teachers for teachers
I would definitely recommend Study.com to my colleagues. It’s like a teacher waved a magic wand and did the work for me. I feel like it’s a lifeline.
Numeric Data Types in C++ Programming
Related Study Materials
- Computer Science 204: Database Programming
- Computer Science 321: Ethical Hacking
- Computer Science 335: Mobile Forensics
- Computer Science 201: Data Structures & Algorithms
- Computer Science 109: Introduction to Programming
- Windows Server Configuration
- Computer Science 303: Database Management
- Computer Science 110: Introduction to Cybersecurity
- Computer Science 320: Digital Forensics
- Computer Science 332: Cybersecurity Policies and Management
- Introduction to JavaScript
- Introduction to HTML & CSS
- Computer Science 203: Defensive Security
- Introduction to SQL
- Computer Science 310: Current Trends in Computer Science & IT
Browse by Courses
- Data Types in Programming: Numbers, Strings and Others
- Types of Data: Text, Numbers & Multimedia
- Java Data Types: Byte
- Overview of Data Types in Java
- What is the Difference Between Phishing and Pharming?
- Asymmetric Threat: Definition & Characteristics
- Computer Animation: Definition, History & Types
- Analytical CRM: Definition & Applications
- SaaS vs. Cloud Computing
- How to Create a Batch File
- What is Privilege Escalation?
- Internet Engineering Task Force (IETF): Standards & Protocol
- Security Perimeter: Definition, Solutions & Devices
- Responsive Web Design: Examples & Explanation
- What is the ASP.NET Web API?
Browse by Lessons
Explore our library of over 88,000 lessons
- Create a Goal
- Create custom courses
- Get your questions answered