Typecasting

Sometimes you create a variable of one data type but actually need to (for one reason or another) use that variable in another context (using an integer as a character, or discarding some precision by using double as a float instead). What to do? One approach is to simply create another variable of the new type with the same exact value, but that seems wasteful. Another option we can take advantage of with C is the ability to cast (temporarily change) one data type into another with the same or less precision (e.g. we can cast a double to a float, but not vice versa), which might be more efficient from a design standpoint. In this section, we briefly examine the mechanism and some use cases for typecasting.