Basic Data Types:
C++ provides a rather large number of types. However, you can write perfectly good programs using only five of those:
Here are some examples of declaring and intializing variables:
int age = 33;
double price = 1.25;
char grade = 'A';
std::string game_output = "Game Over";
bool is_registered_to_vote = true;
As the name implies, datatype modifiers are used with the built-in data types to modify the length of data that a particular data type can hold. Data type modifiers in C++ are:
We will learn about these in a bit!
const (constant) variables cannot be changed by your program during execution.
const double quarter = 0.25;
// and now variable quarter can only be 0.25
Simply add the keyword
const before the data type during declaration to make the variable not modifiable.
A type cast is basically a conversion from one type to another.
(type) value means “convert
type“. So for example:
weight1 = 154.49;
weight2 = (int) weight1;
// weight2 is now 154
Note: Going from a
double to an
int simply removes the decimal. There’s no rounding involved.