0
what is type cast operator
2 Respuestas
+ 1
It is used to change the type of a given variable.
int a = 5;
int b = 2;
When doing a / b the compiler evaluates that to int(a) / int(b) and int / int -> int. So this expression evaluates to 2, which may not be the answer you want.
To get the answer yoy want you need to type cast one of the two variables.
(double)a / b or double(a) / b evaluates to double / int -> double so the answer is 2.5, which is the correct answer.
Anyways, the default type cast operator doesnt always apply. There is a question here from a couple days ago where I asked what types of type cast techniques there are. Stefan gives a really good and understandable answer.
0
it refers to the process of changing the data type of the value stored in a variable