gpt4 book ai didi

c++ - C++中的int(expr)是什么意思?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:18:39 25 4
gpt4 key购买 nike

在查看 friend 项目中的一些代码时,我最近看到了类似这样的语法。

#include <iostream>

int main(){
std::cout<< int(32.5/5) << std::endl;
}

当您运行上面的代码时,您会得到 6,如果使用 int 功能(如强制转换),这是预期值。

但是,我以前从未见过这种语法,也无法在网上找到它的文档。我还做了一个实验,发现这种语法在 C 中无效。

谁能用文档引用解释这个语法的含义?

最佳答案

这不是构造函数调用或“函数”。没有“int 函数”。

这是函数式转换符号it's just a cast .

它与 (int)(32.5/5) 相同(在这种特殊情况下)。

而且,不,C 没有它。

关于c++ - C++中的int(expr)是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28519415/

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