C++ Data Types


C++ Data Types

As explained in the chapter, a variable in C++ must be a specified data type:

Example

int myNum = 5;               // Integer (whole number)
float myFloatNum = 5.99;     // Floating point number
double myDoubleNum = 9.98;   // Floating point number
char myLetter = 'D';         // Character
bool myBoolean = true;       // Boolean
string myText = "Hello";     // String

Basic Data Types

The data type specifies the size and type of information the variable will store:

Data Type Size Description
boolean 1 byte Stores true or false values
char 1 byte Stores a single character/letter/number, or ASCII values
int 2 or 4 bytes Stores whole numbers, without decimals
float 4 bytes Stores fractional numbers, containing one or more decimals. Sufficient for storing 6-7 decimal digits
double 8 bytes Stores fractional numbers, containing one or more decimals. Sufficient for storing 15 decimal digits

You will learn more about the individual data types in the next chapters.


C++ Exercises

Test Yourself With Exercises

Exercise:

Add the correct data type for the following variables:

 myNum = 9;
 myDoubleNum = 8.99;
 myLetter = 'A';
 myBool = false;
 myText = "Hello World";


Basic Data Types

Login
ADS CODE