Lesson 3 of 22
Lesson Progress: 0%
In C++, every piece of data has a type that tells the compiler what kind of value it holds. The most common basic types are int for whole numbers, double for decimal numbers, char for a single character, bool for true or false, and string for text. Choosing the right type is important because it determines what you can do with the data and how much memory it uses. This lesson will introduce each basic data type and show how to use them in your programs.
#include <iostream>
using namespace std;
int main() {
int age = 10;
string name = "Bob";
cout << name << " is " << age;
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
int stores whole numbers like 10 without any decimal part.string stores text like "Bob" and must be in double quotes.Bob is 10.#include <iostream>
using namespace std;
int main() {
double price = 4.99;
cout << "Price: " << price;
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
double stores decimal numbers like 4.99.double when you need to represent fractional values like prices or measurements.Price: 4.99.#include <iostream>
using namespace std;
int main() {
char grade = 'A';
cout << "Grade: " << grade;
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
char stores a single character like 'A'.Grade: A.#include <iostream>
using namespace std;
int main() {
string city = "London";
cout << "City: " << city;
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
string stores a sequence of characters like "London".City: London.#include <iostream>
using namespace std;
int main() {
bool isReady = true;
cout << isReady;
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
bool stores a truth value: either true or false.true shows as 1 and false shows as 0.#include <iostream>
using namespace std;
int main() {
int count = 7;
double cost = 2.5;
cout << count * cost;
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
int count = 7; stores a whole number and double cost = 2.5; stores a decimal.int and a double produces a double result.17.5.Test Incomplete