请解释逗号运算符本计划 [英] Please Explain Comma Operator in this Program

查看:142
本文介绍了请解释逗号运算符本计划的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请解释一下我这个程序的输出:

Please explain me the output of this program:

int main()
{    
    int a,b,c,d;  
    a=10;  
    b=20;  
    c=a,b;  
    d=(a,b);  
    printf("\nC= %d",c);  
    printf("\nD= %d",d);  
}

而我得到的输出是:

The output which I am getting is:

C= 10  
D= 20

我的疑问是什么是,运营商在这里做?结果
我编译和使用code块运行程序。

My doubt is what does the "," operator do here?
I compiled and ran the program using Code Blocks.

推荐答案

运算符计算了一系列的前pressions,并返回​​的最后的值。

The , operator evaluates a series of expressions and returns the value of the last.

C = A,B 相同(C = A),B 。这就是为什么c为10

c=a,b is the same as (c=a),b. That is why c is 10

C =(A,B)将分配 A的结果,B ,这是20日到 C

c=(a,b) will assign the result of a,b, which is 20, to c.

由于迈克在评论中指出,分配( = )具有较高的precedence比逗号

As Mike points out in the comments, assignment (=) has higher precedence than comma

这篇关于请解释逗号运算符本计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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