CPP Tutorial



C++ DATA TYPES


📊 Data Types in C++

In C++, data types tell the compiler what kind of data a variable will store. Different data types help the program use memory efficiently and understand how to handle the data.

Basic Data Types

Data Type Description Example
int Stores whole numbers (integers) like -10, 0, 100. int age = 25;
float Stores decimal numbers with single precision. float price = 99.99;
double Stores decimal numbers with double precision (more accurate than float). double pi = 3.14159;
char Stores a single character like 'A', 'z', or '9'. char grade = 'A';
bool Stores only two values: true or false. bool isPassed = true;
string Stores a sequence of characters (text). string name = "Alice";

Example Program Using Different Data Types

#include <iostream>
#include <string>

using namespace std;

int main() {
  int age = 21;
  float height = 5.7;
  double weight = 68.5;
  char grade = 'A';
  bool isStudent = true;
  string name = "Ravi";

  cout << "Name: " << name << endl;
  cout << "Age: " << age << endl;
  cout << "Height: " << height << " feet" << endl;
  cout << "Weight: " << weight << " kg" << endl;
  cout << "Grade: " << grade << endl;
  cout << "Is Student? " << isStudent << endl;

  return 0;
}
  

Note

To use string, you need to include the <string> library. For input/output operations, include <iostream>.


🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review