0% found this document useful (0 votes)
4 views2 pages

C++ Data Types

The document provides an overview of data types in C++, explaining that variables must have a specified data type. It lists basic data types such as boolean, char, int, float, and double, along with their sizes and purposes. The document also includes an exercise for users to practice identifying the correct data types for given variables.

Uploaded by

Elsa Olivia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

C++ Data Types

The document provides an overview of data types in C++, explaining that variables must have a specified data type. It lists basic data types such as boolean, char, int, float, and double, along with their sizes and purposes. The document also includes an exercise for users to practice identifying the correct data types for given variables.

Uploaded by

Elsa Olivia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

 Tutorials  Exercises  Get Certified  Services  Search...

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

C++ Data Types


❮ Previous Next ❯

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 TutorialsSize
 Exercises  Get Certified 
Description
Services 

Type
HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

boolean 1 byte Stores true or false values

char 1 byte Stores a single character/letter/number, or ASCII values

int 2 or 4 Stores whole numbers, without decimals


bytes

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;

You might also like