To cast, casting


If you want to change the datatype of a variable you have to use a technic called cast. For example if want to change an int to a float you could use the following syntax:

        
    main()
    {
        int var1;
        float var2;

        var2 = (float)var1;
    }

As it happens this example would never be used in practice because C would perform the conversion automatically. What this example does show is the cast operator () . This states, the result of the expression (in this case var1) is to be a data type of float.


See Also:

C++ changes to cast.


Top Master Index Keywords Functions


Martin Leslie