C ++ - 回报X,Y;要点是什么? [英] C++ -- return x,y; What is the point?

查看:142
本文介绍了C ++ - 回报X,Y;要点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C和C ++编程了了几年,现在我只是现在采取了大学课程在里面,我的书有一个例子像这样的功能:

I have been programming in C and C++ for a few years and now I'm just now taking a college course in it and our book had a function like this for an example:

int foo(){
  int x=0;
  int y=20;
  return x,y; //y is always returned
}

我从来没有见过这样的语法。事实上,我从来没有见到过,参数列表外使用运营商。如果总是返回,虽然,那还有什么意义呢?是否存在这样一个return语句将需要这样创建的情况下?

I have never seen such syntax. In fact, I have never seen the , operator used outside of parameter lists. If y is always returned though, then what is the point? Is there a case where a return statement would need to be created like this?

(另外,我标记的c以及因为它适用于,虽然我的书特别是C ++)

(Also, I tagged C as well because it applies to both, though my book specifically is C++)

推荐答案

逗号操作符在主要用于像这样的语句:

The comma operator is primarily used in for statements like so:

for( int i=0, j=10; i<10; i++, j++ )
{
    a[i] = b[j];
}

第一个逗号不是逗号操作符,它的声明语法的一部分。第二个的的逗号操作符。

这篇关于C ++ - 回报X,Y;要点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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