0% found this document useful (0 votes)
5 views

C++ Data Types

Uploaded by

junlight55
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)
5 views

C++ Data Types

Uploaded by

junlight55
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

11/10/2022, 19:41 C++ Data Types

Dark code
  HTML CSS   
 Menu  Log in

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 Size Description


Type Dark mode
https://www.w3schools.com/cpp/cpp_data_types.asp D k d 1/7
11/10/2022, 19:41 C++ Data Types
Dark code
 boolean
 1 byte CSS Stores true or false values
HTML   
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 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";

Submit Answer »

Dark mode
Start the Exercise
https://www.w3schools.com/cpp/cpp_data_types.asp D k d 2/7

You might also like