未使用的函数返回值会发生什么? [英] What happens to unused function return values?

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

问题描述

如果我有一个程序:

#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 ,b),因为它未被使用?

推荐答案

;表达式 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天全站免登陆