In certain situations, some variables are declared as integers but sometimes it may be required to get the result as floating point numbers.
The type conversion is to convert the set of declared type to some other required type.
It is easy to convert values from one type to another type in a C++ program.
For example ,
assume that the following type has been declared......
The question arises whether....x =y ;
where x is an integer type and y is a floating point type, is a valid assignment.
Since here problem arises of converting of one
For such a case two conversion are carried out:
(1) Converting by assignment : It is a usual way of converting a value from one data type to another by using the assignment operator (equal to sign)
For example assume following thing has been declared:
and we have statement x=y;
yes the above statement written will
For this we use the Cast operator
(2) Cast operator : The cast operator is the technique of converting forcefully one data type to another. The operator used is the cast operator and process is known as 'casting'....
The cast operator takes on the format :
for example, to force a floating point number to integer,
we would use....
result = (int)(19.2/4);
or result = int(19.2/4);
For more of such hot topics read my other posts here :
Visit my new website