我有两个变量:
int a;
uint b;
我还有一个数组:
float c[100];
如果我想将 a+b
作为数组 c
的索引传递:
c[a+b] = 10.0;
为了安全起见,我们应该确保a+b
返回uint
。它是否返回 unit
?
我应该强制它的返回值是一个uint
吗?
最佳答案
是的,当您添加一个 int
和一个 unsigned int
时,int
值会提升为 unsigned int
,所以你会没事的。但是,请注意 a 不是负数,否则您会大吃一惊!
关于c - int加uint的返回值是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28133422/