Page 03
C++
Variables and Data Types
Core idea Variables store data, and data types tell C++ what kind of value each variable can hold. This is the first step toward writing programs that actually work with informatio...
Core idea
Variables store data, and data types tell C++ what kind of value each variable can hold. This is the first step toward writing programs that actually work with information.
Common beginner types
intfor whole numbersdoublefor decimal numberscharfor a single characterboolfortrueorfalsestd::stringfor text
#include <iostream>
#include <string>
int main() {
int age = 20;
double price = 19.99;
char grade = 'A';
bool isReady = true;
std::string name = "Prathmesh";
std::cout << name << " is " << age << " years old.\n";
}
Revision points
- A variable has a type, a name, and usually a starting value.
- Choose names that explain the value clearly.
- Use
std::stringwhen working with words or sentences. - Start with simple values before combining them inside larger programs.
What to remember
Pick the simplest type that matches the data you are working with.
Next step
After variables make sense, control flow shows you how programs make decisions.