gpt4 book ai didi

c - int加uint的返回值是多少?

转载 作者:太空宇宙 更新时间:2023-11-04 02:45:14 30 4
gpt4 key购买 nike

我有两个变量:

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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com