gpt4 book ai didi

c - 将 int 重新分配给 const int?

转载 作者:太空狗 更新时间:2023-10-29 15:14:14 26 4
gpt4 key购买 nike

我正在阅读一个 C 代码库,我发现了一个看起来像这样的片段:

void foo(int bar) {
const int _bar = bar;
...
}

然后作者在其余代码中使用了 _bar。为什么这样做?是优化还是有其他原因?

最佳答案

The author then uses _bar throughout the rest of the code.

如果一直使用 _bar 而不是使用函数参数,我会用 const 限定函数参数。

void foo( const int bar )
{
// use bar but modifications to bar itself are not allowed.
}

关于c - 将 int 重新分配给 const int?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9435401/

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