什么是INT加UINT的返回值? [英] What is the return value of int plus uint?

查看:167
本文介绍了什么是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!

这篇关于什么是INT加UINT的返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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