Can a float value be used as the index of an array? What will happen if an expression used as an index resulted to a float value?
Yes. But it's pointless. The float value will be truncated to an integer.
Floats cannot be used as indices.
fill(float[] a, float val) method assigns the specified float value to each element of the specified array of floats.
Any float or real expression is considered imprecise and cannot be a key of an index; a float or real expression can be used in an indexed view but not as a key.
The float value will be casted to int (it can give warning or error depending on compiler's warning level)
s1 = q[12.2]; // same as q[12]
s2 = q[12.999999]; // same as q[12]
s3 = q[12.1/6.2]; // same as q[1]
Yes. But it's pointless. The float value will be truncated to an integer.
(You can use std::map<float, T>
, however, but most of the time you'll miss the intended values because of inaccuracy.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With