VARIABLES
A variable is a container (storage area) used to hold data.
Each variable should be given a unique name (identifier).
int a=2;
Here a is the variable name that holds the intege
r 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 keyword).
Fundamental Data Types in C++
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.
1. int
- x This data type is used to store integers.
- x It occupies 4 bytes in memory.
- x It can store values from -2147483648 to 2147483647.
Eg. int age = 18
2. float and double
- x Used to store floating-point numbers (decimals and exponentials)
- x Size of the float is 4 bytes and the size of double is 8 bytes.
- x Float is used to store up to 7 decimal digits whereas double is used
- to store up to 15 decimal digits.
Eg. float pi = 3.14
double distance = 24E8 // 24 x 108
3. char
- x This data type is used to store characters.
- x It occupies 1 byte in memory.
- x Characters in C++ are enclosed inside single quotes ͚ ͚.
- x 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
Derived Data Types
These are the data types that are derived from fundamental (or built-in) data
types. For example, arrays, pointers, function, reference.
User-Defined Data Types
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.
Copywrite claim CODEHOVER https://makhdoomusman.blogspot.com/2021/10/variables-variable-is-container-storage.html