Course Content
C++ Introduction
C++ Introduction
Data Types
When declaring a variable, you need to specify what type of data we will store in it. There are data types for easy memory handling for every situation.
Integer Types | |||
---|---|---|---|
int | |||
short | |||
Floating Point Types | |||
float | |||
double | |||
Character Types | |||
char | |||
string | |||
Other Types | |||
bool | |||
void |
Numerical
These types are essential for storing numerical values and performing mathematical operations. They are divided into two main groups: integer types, which store whole numbers, and floating-point types, which store numbers with fractional parts.
integers
decimals
// examples of literal integers 5 100 30
Bool
The bool
data type represents two boolean values: zero interpreted as false and one is interpreted as true.
Char
The char
data type is used to store individual characters, which can include letters, digits, punctuation marks, and special characters. These characters must be enclosed in single quotes ('
), such as 'A'
, '9'
, or '!'
.
Void
The void
data type represents the absence of a value. It is primarily used for functions that do not return any data. When a function is declared as void
, it means the function performs an action but does not provide a result.
Note
The use and purpose of
void
will be explored further in the chapter about functions.
You can check the data type of certain expressions using the code below. Feel free to experiment with it.
main
#include <iostream> #include <typeinfo> // Provides tools for type identification int main() { // `typeid().name()` gives you the type of expression // Replace `___` with a number, boolean (true/false), or character std::cout << "The data type is " << typeid(___).name() << std::endl; }
Thanks for your feedback!