未使用的函数返回值会怎样? [英] What happens to unused function return values?

查看:21
本文介绍了未使用的函数返回值会怎样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个程序:

#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.

这篇关于未使用的函数返回值会怎样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆