- Data types are just like initials.
- Data types are the kind of data that the variable use in programming languages.
- Generally the data types are classified as
- The data type "int" holds 2 byte values, whereas "float" holds 4 bytes, and "char" data type holds 1 byte and "double" data type holds 8 bytes.
- A particular variable can point to a single data type throughout the program.
- The concept of data type differs when we use a templates
- When we use templates, a variable may point to a unknown data type. (i.e) a generic pointer.
- Variables are the memory location that the variable use in programming languages.
- A variable can be name of a person, or anything else.A user defined name can be defined to a variable.
- Rules for declaring a variables:
- The variable must starts with an alphabet or an underscore i.e( _ ) followed by alphabets or numbers.
- No special characters except underscore should be used.
- The special words or reserved words i.e the keywords should not be used.
Declaring variable while using templates
template <class a>
cout<<"enter a integer value";
cout<<"enter a float value";
cout<<"enter a char value";
The above program is implemented using templates.Here the variable "ex" is of generic type.(i.e) unknown data type.
Hence it can take values for integer, or float, or character.
Values to a variable can be assigned in two ways:
i) Direct assignment
ii) Run time assignment
Direct assignment to a variable is nothing but initialization of variables.
eg: int num=10;
Here the variable num takes the value 10 initially.Since it is a variable the value may be changed.
Run time assignment:
The values for the variables can be read from the user during the runtime.
(i.e) char name;
cout<<"enter your name";
Fear is a reaction,but courage is a destination