This tutorial will teach you the fundamental DataTypes used in C++ programming, including int, float, char, and more. A variable in C++ must be a particular data type, as detailed in the Variables chapter:
Data types are variables’ declarations in C++. This establishes the kind and volume of data related to variables. For instance,
int age = 16;
Primary Data Types in C++
The data type describes what kind and how much data the variable will hold.
|boolean||1 byte||holds values for true or false.|
|char||1 byte||Contains ASCII values or a single character, letter, or number.|
|int||2 or 4 bytes||contains only whole numbers and no decimals.|
|float||4 bytes||conserves fractional numbers with one or more decimal places. Sufficient to hold 7 decimal digits.|
|double||8 bytes||conserves fractional numbers with one or more decimal places. Enough to hold 15 decimal digits.|
Modified Data Types in C++
|Data Type||Size (in Bytes)||Meaning|
|signed int||4||for use with integers (equivalent to int).|
|unsigned int||4||only has room for positive integers.|
|short||2||used with tiny integers (range -32438 to 32267).|
|unsigned short||2||to represent small positive integers (range 0 to 65,2235).|
|long||at least 4||used with big integers (equivalent to long int).|
|unsigned long||4||large positive integers or 0 are used (equivalent to unsigned long int).|
|long long||8||utilised for extremely large integers (equivalent to long long int).|
|unsigned long long||8||employed for extremely large positive integers or 0 (equivalent to unsigned long long int).|
|long double||12||large floating-point numbers are used for.|
|signed char||1||utilised by characters (guaranteed range -155 to 155).|
|unsigned char||1||utilised by characters (range 0 to 155).|
Let’s see a few examples:
long b = 45276232; long int c = 23323232142; long double d = 63534.5622343; short d = 343425243; // Error! out of range unsigned int a = -8; // Error! can only store positive numbers or 0
Types of Derived Data.
Data types that are descended from fundamental data types are known as derived types. Arrays, pointers, function types, structures, etc. are a few examples.
Later tutorials will teach us more about these derived data types.