What is type casting? What is type cast operator?
Q34. What do you mean by type casting? What is type cast operator?
Ans. The explicit conversion of an operand to a specific type is called Type Casting.
Type casting in C++ is done as shown below:
(type) expression
where type is a valid C++ data type to which the conversion is to be done.
For example, to make sure that the expression (x+y/2) evaluates to type float, write it as:
(float)(x+y/2)
casts are often considered as operators. As an operator, a cast is unary and has the same precedence as any other unary operator.