Tsallaka zuwa abun ciki
Justice Tech School

Variables and Types

Declare a variable with its type: int, double, char, bool or string. auto lets the compiler work out the type. const makes a value fixed. Use curly brace initialisation to avoid accidental narrowing.

Example
int age = 21;
double price = 19.99;
char grade = 'A';
bool active = true;
string name = "Ada";
const int MAX = 100;
auto city = string("Lagos");
cout << name << " " << age << " " << grade << " " << price << " " << active << " " << MAX << " " << city << endl;

Result

Ada 21 A 19.99 1 100 Lagos

Exercise

Let the compiler pick the type.

 x = 5;

Quiz Test

Which keyword makes a value fixed?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.