More about C++ Data Types

Before discussing data types in C++, you should know the word datatype. So what is a data type? It is the type of data that a variable can store in the form of value. It can be of any kind, i.e., numerical data, textual data, character data, etc. I hope you got it. If you still have any queries related to datatypes, comment below. Now let’s discuss datatypes in C++.

Data Types

There are several data types in C++ look below:

Data typeSize of DatatypeDescription of data type
int2 or 4 bytesStores whole numbers, without decimals / positive or negative
float4 bytesStores fractional numbers, containing one or more decimals. Sufficient for storing 6-7 decimal digits
double8 bytesStores fractional numbers, containing one or more decimals. Sufficient for storing 15 decimal digits
char1 byteStores a single character/letter/number, or ASCII values and it is surrounded by single comma like ‘a’
boolean1byteStores true or false values or on or off like
Basic C++ Data Types
Data Types

Declaring Variable with data types in C++ with output

#include <iostream>
#include <string>
using namespace std;
 
int main () {
  // Creating variables and storing value depend on the data type
  int myNum = 500;               // Integer (whole number)
  float myFloatNum = 5.999;     // Floating point number
  double myDoubleNum = 9.99998;   // Floating point number
  char myLetter = 'A';         // Character
  bool myBoolean = true;       // Boolean
  string myString = "Codelikechamp.com";   // String
   
  // Print variable values
  cout << "int: " << myNum << "\n";
  cout << "float: " << myFloatNum << "\n";
  cout << "double: " << myDoubleNum << "\n";
  cout << "char: " << myLetter << "\n";
  cout << "bool: " << myBoolean << "\n";
  cout << "string: " << myString << "\n";
 
  return 0;
}

Output

int: 500
float: 5.999
double: 9.99998
char: A
bool: 1
string: Codelikechamp.com

Link: https://Codelikechamp.com

Medium Link: Follow me on Medium

Linkedin Link: Follow me on Linkedin

🤞 Don’t miss any latest posts!

Please subscribe by joining our community for free and stay updated!!!

IF YOU HAVE ALREADY SUBSCRIBED JUST CLOSE THIS FORM !

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top