Thuta Learning
BasicProgrammingbeginner

Data Types

Relax. We'll talk through this in plain words — no textbook voice.

A data type defines what kind of data a variable can hold. Choosing the right data type matters for memory usage, calculation accuracy, and how easy your code is to read.

cpp
#include <iostream>
#include <string>
using namespace std;

int main() {
    int students = 35;
    double averageMark = 82.75;
    char section = 'B';
    bool passed = true;
    string course = "C++ Foundation";

    cout << course << endl;
    cout << "Students: " << students << endl;
    cout << "Average: " << averageMark << endl;
    cout << "Section: " << section << endl;
    cout << "Passed: " << passed;
    return 0;
}

int is for whole numbers, double is for decimal numbers, char is for a single character, bool is for true/false, and string is for text. For data that doesn't need decimals, like a student count, int is the better fit.

You should see
C++ Foundation Students: 35 Average: 82.75 Section: B Passed: 1

Info

For decimal values like money, grade averages, or measurements, double is used more often than float.

Easy traps

  • Writing int price = 19.99; can silently drop the decimal part. Keep in mind that using the wrong data type can give you incorrect results.
Data Types | Thuta Learning