In C++, primitive data types are the built-in types that form the backbone of programming. Like a chemical compound, where different elements combine to form a large complex structure, in programming different data types combine to form complex algorithms and structures. Understanding them is pivotal in mastering C++. Here are some of the common data types:
int: Used for storing an integer. For example, if you are tracking the number of transactions in a blockchain, you might use
int
.float: Used for storing decimal numbers. For example, when you need to store the price of a stock,
float
can be useful.bool: This is a boolean type and can hold either
true
orfalse
. It's often used in logical operations or loops.char: Used for storing a single character. This could be part of a piece of string data, like the name of a company for a finance application.
You can declare a variable by specifying its type, followed by the variable name. For instance, int count;
declares a variable named count
of type int
. The variable can then be assigned a value using the assignment operator (=)
. For example: count = 10;
.

xxxxxxxxxx
using namespace std;
int main() {
int transactions = 100;
float stock_price = 200.50;
bool isProfit = true;
char company_name_initial = 'A';
cout << transactions << endl;
cout << stock_price << endl;
cout << isProfit << endl;
cout << company_name_initial << endl;
}