• Home
  • Jobs
  • Courses
  • Certifications
  • Companies
  • Online IDE
  • Login
  • Signup
MYTAT
  • Home
  • Jobs
  • Courses
  • Certifications
  • Companies
  • Online IDE
  • Login
  • Signup
C++
  • C++ Introduction
  • C++ Getting Started
  • C++ Syntax
  • C++ Output (Print Text)
  • C++ Comments
  • C++ Variables
  • C++ Declare Multiple Variables
  • C++ Identifiers
  • C++ User Input
  • C++ Data Types
  • C++ Operators
  • C++ Strings
  • C++ Math
  • C++ Booleans
  • C++ Conditions
  • C++ Switch
  • C++ While Loop
  • C++ For Loop
  • C++ Break And Continue
  • C++ Arrays
  • C++ References
  • C++ Pointers
  • C++ Functions
  • C++ Function Overloading
  • C++ OOP
  • C++ Classes And Objects
  • C++ Class Methods
  • C++ Constructors
  • C++ Access Specifiers
  • C++ Encapsulation
  • C++ Inheritance
  • C++ Multilevel Inheritance
  • C++ Multiple Inheritance
  • C++ Inheritance Access
  • C++ Polymorphism
  • C++ Files
  • C++ Exceptions
  • C++ How To Add Two Numbers
  • Home
  • Courses
  • C++
  • C++ Data Types

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 now



Practice Excercise Practice now

Basic Data Types

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

Data Type Size Description
int 4 bytes Stores whole numbers, without decimals
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
boolean 1 byte Stores true or false values
char 1 byte Stores a single character/letter/number, or ASCII values



Practice Excercise Practice now

C++ Numeric Data Types

Use int when you need to store a whole number without decimals, like 35 or 1000, and float or double when you need a floating point number (with decimals), like 9.99 or 3.14515.

int

int myNum = 1000;
cout << myNum;


Try it now


float

float myNum = 5.75;
cout << myNum;


Try it now


double

double myNum = 19.99;
cout << myNum;


Try it now


Scientific Numbers

A floating point number can also be a scientific number with an "e" to indicate the power of 10:
 

Example

float f1 = 35e3;
double d1 = 12E4;
cout << f1;
cout << d1;

Try it now

 



Practice Excercise Practice now

C++ Boolean Data Types

A boolean data type is declared with the bool keyword and can only take the values true or false. When the value is returned, true = 1 and false = 0.

Example

bool isCodingFun = true;
bool isFishTasty = false;
cout << isCodingFun;  // Outputs 1 (true)
cout << isFishTasty;  // Outputs 0 (false)

Try it now

 



Practice Excercise Practice now

C++ Character Data Types

The char data type is used to store a single character. The character must be surrounded by single quotes, like 'A' or 'c':

Example

char myGrade = 'B';
cout << myGrade;

Try it now

Alternatively, you can use ASCII values to display certain characters:

Example

char a = 65, b = 66, c = 67;
cout << a;
cout << b;
cout << c;

Try it now



Practice Excercise Practice now

C++ String Data Types

The string type is used to store a sequence of characters (text). This is not a built-in type, but it behaves like one in its most basic usage. String values must be surrounded by double quotes:

Example

string greeting = "Hello";
cout << greeting;
 

To use strings, you must include an additional header file in the source code, the <string> library:

Example

// Include the string library
#include <string>

// Create a string variable
string greeting = "Hello";

// Output string value
cout << greeting;

Try it now



Practice Excercise Practice now

Previous Next
COMPANY
  • About us
  • Careers
  • Contact Us
  • In Press
  • People
  • Companies List
Products
  • Features
  • Coding Assessments
  • Psychometric Assessment
  • Aptitude Assessments
  • Tech/Functional Assessments
  • Video Assessment
  • Fluency Assessment
  • Campus
 
  • Learning
  • Campus Recruitment
  • Lateral Recruitment
  • Enterprise
  • Education
  • K 12
  • Government
OTHERS
  • Blog
  • Terms of Services
  • Privacy Policy
  • Refund Policy
  • Mart Category
Partner
  • Partner Login
  • Partner Signup

Copyright © RVR Innovations LLP 2025 | All rights reserved - Mytat.co is the venture of RVR Innovations LLP