Initially variable salary is defined as float but for the above calculation it is first converted to double data type and then added to the variable bonus.
A number which does not charge its value during execution of a program is known as a constant.
Floating Point Numerals
Character and string literals
Any attempt to change the value of a constant will result in an error message. A constant in C++ can be of any of the basic data types.
const qualifier can be used to declare constant as shown below:
The above declaration means that Pi is a constant of float types having a value 3.1415.
Examples of valid constant declarations are:
A variable is the most fundamental aspect of any computer language.
Variable are used in C++, where we need storage for any value, which will change in program.
It is a location in the computer memory which can store data and is given a symbolic name for easy reference.
The variables can be used to hold different values at different values at different times during the execution of a program.
To understand more clearly we should study the following statements:
For example, a variable Total of type float can be declared as shown below:
Similarly the variable Net can also be defined as shown below:
Examples of valid variable declarations are:
(i) int count;
(ii) int i, j, k;
(iii) char ch, first;
(iv) float total, Net;
(v) long int sal;