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 int8bytes-2,147,483,648 to 2,147,483,647
signed long int8bytessame as long int
unsigned long int8bytes0 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

close

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.

Related posts
C++C++11C++14C++17Introduction to C++Learn C++

Discover Function Overloading in C++

C++Learn C++Videos

Learn C++ With Back to Basics: Move Semantics by David Olsen (CPPCon 2020) Video

C++Introduction to C++Learn C++

Learn to Use Pointers and Memory Address of a Variable in C++

C++Introduction to C++Learn C++

Discover Goto and Labels in C++

en_USEnglish