The following code converts the float type 7.5
to an integer value 7
, the remainder is lost. Here, the typecasting operator is int
. I know it is valid typecast in C++.
int main()
{
int i;
float f = 7.5;
i = (int) f; // Valid in C/C++
}
But another way to do the same thing in C/C++
is to use the functional notation preceding the expression to be converted by the type and enclosing the expression between parentheses:
i = int (f); // It is worked in C++ but not C
So, I have a question, Is it valid way to typecast in C++?