gpt4 book ai didi

c++ - 位补函数在 C++ 的 For 循环中做什么?

转载 作者:行者123 更新时间:2023-12-01 14:04:37 25 4
gpt4 key购买 nike

以这行代码为例:for(int i=n-1; ~i; --i)我的问题是 ~i 是什么?意思。我已经知道 for 循环需要以下内容:

for (type var = ; condition; something to do with var) {
code here
}

但是如何 ~i一个条件?
我只知道 ~i返回 i 的按位补码,或翻转位。

最佳答案

在整数的 2-compliment 表示中,这个循环

for(int i=n-1; ~i; --i)

相当于
for(int i=n-1; i != -1; --i)

关于c++ - 位补函数在 C++ 的 For 循环中做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61034128/

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