Float Values as an index in an Array in C++

c++

Solution

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]

Problem

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?

Original source