Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有两个变量:
int a; uint b;
我也有一个数组:
float c[100];
如果我想a+b作为数组的索引传递,c那么:
a+b
c
c[a+b] = 10.0;
为了安全起见,我们应该确保a+b退货uint。它回来了unit吗?
uint
unit
我应该强制它的返回值是一个uint吗?
是的,当你添加 anint和 anunsigned int时,int值会提升为unsigned int,所以你会没事的。但是,请注意 a 不是负数,否则您会大吃一惊!
int
unsigned int