your image

C++ Data Types

W3 Schools
W3 Schools.com5
Related Topic
:- C++ language programming languages

C++ Data Types

PreviousNext

C++ Data Types

As explained in the Variables 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

Try it Yourself »

Basic Data Types

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

Data TypeSizeDescriptionint4 bytesStores whole numbers, without decimalsfloat4 bytesStores fractional numbers, containing one or more decimals. Sufficient for storing 7 decimal digitsdouble8 bytesStores fractional numbers, containing one or more decimals. Sufficient for storing 15 decimal digitsboolean1 byteStores true or false valueschar1 byteStores a single character/letter/number, or ASCII values

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";


Submit Answer »

Start the Exercise

 

PreviousNext

 

 

NEW

We just launched
W3Schools videos

Explore now

COLOR PICKER

 

LIKE US

Comments