What happens to unused function return values?(未使用的函数返回值会怎样?)
问题描述
如果我有一个程序:
#include <iostream>
using namespace std;
int TestIntReturn(int &x, int &y)
{
x = 1000;
y = 1000;
return x+y;
}
int main()
{
int a = 1;
int b = 2;
cout << a << " " << b << endl;
TestIntReturn(a,b);
cout << a << " " << b << endl;
}
TestInReturn(a,b)
的返回值没有被使用会怎样?
what happens to the return value of TestInReturn(a,b)
since it is unused?
推荐答案
它被丢弃;表达式 TestInReturn(a,b)
是一个丢弃值表达式.丢弃 int
无效,但丢弃 volatile int
(或任何其他 volatile 限定类型)可能会产生从内存读取的效果.
It is discarded; the expression TestInReturn(a,b)
is a discarded-value expression. Discarding an int
has no effect, but discarding a volatile int
(or any other volatile-qualified type) can have the effect of reading from memory.
这篇关于未使用的函数返回值会怎样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:未使用的函数返回值会怎样?


- STL 中有 dereference_iterator 吗? 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 静态初始化顺序失败 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 近似搜索的工作原理 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- C++ 协变模板 2021-01-01
- 从python回调到c++的选项 2022-11-16