Introduction to C++Learn C++Syntax

Quickly Learn About Data Types And Size Of Variables In The C++ Programming Language

In C++ Programming Language, the information is stored with the various data types like character, wide character, integer, floating point, double floating point, boolean etc.
When coding in any programming language, we need to use various variables to store various information. Each variable reserves a location in memory, reading a variable from this memory location or writing a variable to this memory location takes time and they took space in the memory.

In Today’s technology when we have Petabytes and over 5+ Ghz CPUs and RAMs in frequencies, these may seem like no meaning but a good program is the optimized program by developer and everything makes sense on runtime. This reading and writing operations may be took 1/millions of seconds or milliseconds, and users has RAM memory in GBs. But for example when you use same function million of times with same variables that makes difference. Probably your function or algorithm will work slow, or some variables may exceed their limits or it will cost a lot of memory. These small details may make big changes in high quality applications. i.e. Data Transferring, Data Storing, Data Mining, Image Processing, Face Detection, AI Technologies, Video Streaming and Coding/Decoding Operations etc.

So, a good developer should know size of data types and their limits Because based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory.

Primitive Built-in Types

These are the basic C++ data types

boolBoolean ( True or False)
charCharacter in ASCII Mode ( 0 to 255)
intInteger Number
floatFloating Point Number
doubleDouble Floating Point Number
voidValueless
wchar_tWide character

We can use int, float, double with prefixes signed, unsigned, short, long, long long.

Size of Variable Types

Here is the full table shows the variable type, how much memory it takes to store the value in memory, and what is maximum and minimum value which can be stored in such type of variables.

TypeTypical Bit WidthTypical Range
char1byte-127 to 127 or 0 to 255
unsigned char1byte0 to 255
signed char1byte-127 to 127
int4bytes-2147483648 to 2147483647
unsigned int4bytes0 to 4294967295
signed int4bytes-2147483648 to 2147483647
short int2bytes-32768 to 32767
unsigned short int2bytes0 to 65,535
signed short int2bytes-32768 to 32767
long int4bytes-2,147,483,648 to 2,147,483,647
signed long int4bytessame as long int
unsigned long int4bytes0 to 4,294,967,295
long long int8bytes-(2^63) to (2^63)-1
unsigned long long int8bytes0 to 18,446,744,073,709,551,615
float4bytes
double8bytes
long double12bytes
wchar_t2 or 4 bytes1 wide character

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

C++C++11C++14C++17Introduction to C++Learn C++Syntax

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

C++C++11C++14C++17C++20Introduction to C++Learn C++

How To Learn The Move Constructors In Modern C++?