Lesson 2
Variables and Data Types
Variables store data in memory. In C++, every variable has a type that tells the compiler what kind of value it holds.
intfor whole numbersdoublefor decimal numberscharfor a single characterboolfor true or falsestringfor text
Common Data Types
Example
Example
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name = "Alice";
int age = 20;
double score = 88.5;
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
cout << "Score: " << score << endl;
return 0;
}Try it yourself:
Create variables for your own name, age, and favourite subject, then display them on the screen.
Book Tip:
This short lesson is part of a larger learning path. The full book expands each topic with more explanation, exercises, and projects.