Type Conversions


Implicit type conversion is done automatically by the compiler whenever data from different types is intermixed.

Casting: Request by the programmer to do an explicit type conversion.


Example 1: Casting

#include <iostream>
int main()
        using namespace std;
        int nValue1 = 10; 
        int nValue2 = 4;
        float fValue1 = nValue1 / nValue2;
        cout << fValue1 << endl;
        float fValue2 = static_cast<float> (nValue1) / nValue2;
        cout << fValue2 << endl;
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.