2.1 Data Types Notes
2.1 Data Types Notes
int a=2;
Here a is
the
variable
name that
holds the
integer
value 2.
The value
of a can be
changed,
hence the
name
variable.
There are
certain
rules for
naming a
variable in
C++
1. Can only
have
alphabets,
numbers
and
underscore.
2. Cannot begin with a number.
3. Cannot begin with an uppercase character.
4. Cannot be a keyword defined in C++ language (like int is a
Data types are declarations for variables. This determines the type and size
of data associated with variables which is essential to know since different
data types occupy different size of memory.
Data Type Meaning Size (in Bytes)
int Integer 4
float Floating-point 4
char Character 1
bool Boolean 1
void Empty 0
1. int
ξ This data type is used to store integers.
ξ It occupies 4 bytes in memory.
ξ It can store values from -2147483648 to 2147483647.
Eg. int age = 18
3. char
ξ This data type is used to store characters.
ξ It occupies 1 byte in memory.
ξ Characters in C++ are enclosed inside single quotes ͚ ͚.
ξ ASCII code is used to store characters in memory.
Eg͘ char ch с ͚a͖͛
4. bool
ξ This data type has only 2 values ʹ true and false.
ξ It occupies 1 byte in memory.
ξ True is represented as 1 and false as 0.
Eg. bool flag = false
These are the data types that are derived from fundamental (or built-in) data
types. For example, arrays, pointers, function, reference.
These are the data types that are defined by user itself.
For example, class, structure, union, enumeration, etc.
We will be studying the derived and user-defined data types in detail in the
further video lectures.