+ 3
What is the meaning of the following statement in c or c++ ?
int a(float);
1 ответ
- 1
the float in parenthesis is called a typecast, but it is normally preceeding the variable that it is . to change the type of.
Bottom line is that 'a' will be an integer. It is unnecessary to typecast 'a' to a float and assign it as an integer value.
If 'a' were a string containing only numbers, it could be turned into a float type in the following manner:
float val = aFloat.parse(a);
The capital F is required, because this is the class Float and not the native data type float.
Okay, here is an example of a typecast.
int x = 5;
float y = 3.0000f
// we want to divide x by y
// without typecast we cannot, as it will produce an error.
int z = x / (int)y; //z = 1
float z = (float)x / y; // z = 1.6666
Hoped that helped some!