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.

About author

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
C++C++11C++14C++17Introduction to C++Learn C++

This Is How To Get A Substring of a Wide String in C++

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

How To Access Individual Character Elements Of A C++ String

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

The Right Way To Access Character Elements Of A Wide String

C++Language FeatureLearn C++

You NEED to Learn To Use JSON (JavaScript Object Notation)

en_USEnglish