在一行中的多个作业 [英] Multiple assignment in one line

查看:94
本文介绍了在一行中的多个作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚碰到的声明在嵌入式C(dsPIC33系列)

I just come across the statement in embedded c (dsPIC33)

sample1 = sample2 = 0;

请问这意味着

sample1 = 0;

sample2 = 0;

为什么他们键入这样说?这究竟是好还是坏的编码?

Why do they type it this way? Is this good or bad coding?

推荐答案

请记住,分配做从右到左,他们是正常的前pressions。因此,从编译器的角度行

Remember that assignment is done right to left, and that they are normal expressions. So from the compilers perspective the line

sample1 = sample2 = 0;

是相同的

sample1 = (sample2 = 0);

这是相同的

sample2 = 0;
sample1 = sample2;

这就是 SAMPLE2 分配为零,则 SAMPLE1 分配的价值SAMPLE2 。在实践中一样,你猜到分配都为零。

That is, sample2 is assigned zero, then sample1 is assigned the value of sample2. In practice the same as assigning both to zero as you guessed.

这篇关于在一行中的多个作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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