0
0
C++programming~5 mins

Built-in data types in C++

Choose your learning style9 modes available
Introduction

Built-in data types let you store different kinds of information in your program, like numbers or letters.

When you need to store whole numbers like counting apples.
When you want to store decimal numbers like prices or measurements.
When you want to store single characters like a letter or symbol.
When you want to store true or false values to make decisions.
When you want to store larger numbers or precise decimal values.
Syntax
C++
type variableName;

// Examples:
int age;
double price;
char letter;
bool isOpen;

type is the kind of data you want to store.

variableName is the name you give to your storage box.

Examples
This stores the whole number 10 in a variable named count.
C++
int count = 10;
This stores a decimal number 36.5 in temperature.
C++
double temperature = 36.5;
This stores a single letter 'A' in grade.
C++
char grade = 'A';
This stores a true/false value indicating if it is raining.
C++
bool isRaining = false;
Sample Program

This program creates variables of different built-in types and prints their values.

C++
#include <iostream>

int main() {
    int apples = 5;
    double price = 1.25;
    char firstLetter = 'A';
    bool isOpen = true;

    std::cout << "Apples: " << apples << "\n";
    std::cout << "Price: $" << price << "\n";
    std::cout << "First letter: " << firstLetter << "\n";
    std::cout << "Store open? " << (isOpen ? "Yes" : "No") << "\n";

    return 0;
}
OutputSuccess
Important Notes

Use int for whole numbers without decimals.

Use double for numbers with decimals.

Use char for single characters inside single quotes.

Use bool for true or false values.

Summary

Built-in data types store basic kinds of information.

Common types include int, double, char, and bool.

Choose the type based on the kind of data you want to keep.