什么是INT加UINT的返回值?
问题描述:
我有两个变量:
int a;
uint b;
我也有一个数组:
I also have an array:
float c[100];
如果我想通过 A + B
作为数组的索引 C
这样:
If I want to pass a+b
as the index of array c
such that:
c[a+b] = 10.0;
为了安全,我们应该确保 A + B
收益 UINT
。是否返回单元
?
我应该强迫其返回值是一个 UINT
?
Should I force its return value to be an uint
?
答
是的,当你添加一个 INT
和 unsigned int类型
的 INT
价值提升为 unsigned int类型
,所以你会没事的。要小心,一不为负,然而,你还是会在一个讨厌的惊喜!
Yes, when you add an int
and an unsigned int
, the int
value gets promoted to unsigned int
, so you'll be fine. Be careful that a isn't negative, however, or you'll be in for a nasty surprise!