将值作为C ++中的数组的索引 [英] Float Values as an index in an Array in C++

查看:95
本文介绍了将值作为C ++中的数组的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浮点值可以用作数组的索引吗?如果用作索引的表达式导致浮点值,会发生什么?

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?

推荐答案

float值将被转换为int它可以根据编译器的警告级别发出警告或错误)

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]

这篇关于将值作为C ++中的数组的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆