Casting - C++

You might find it necessary at times to convert from one variable type to another. You accomplish this with casting. (Casting, sometimes called type casting, is the act of converting data from one type to another, retaining almost the same value.) Sometimes particular data types are required for certain libraries (which is often the case in DirectX programming). Here is the format for casting from one data type to another:

This snippet of code makes roundedPi equal to 3. The decimal is truncated. Note that the value is not rounded to the nearest one. The decimal is simply removed.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

C++ Topics