What happens to unused function return values?

后端 未结 7 1616
太阳男子
太阳男子 2020-12-10 16:48

If I have a program:

#include 

using namespace std;

int TestIntReturn(int &x, int &y)
{
    x = 1000;
    y = 1000;
    return x+y;         


        
7条回答
  •  一向
    一向 (楼主)
    2020-12-10 17:33

    Everybody answered correctly - the return value in this case is simply discarded, and in this specific example, you can ignore it.

    However, if the return value is a pointer to memory allocated inside the function, and you ignore it, you'll have a memory leak.

    So some function values you can't just ignore, but in this case - you can.

提交回复
热议问题