在为诸如Arduino之类的微型程序进行编程时,我只是C的临时用户,但我有兴趣加深对白话文的理解。
我知道您可以将
this.rotation.interpolate({
inputRange: [0, 360],
outputRange: ['0deg', '360deg'],
extrapolate: 'clamp'
})
简化为1. 337.38055647641903
2. 335.202973299875
3. 13.03761189748721
4. 13.042704554861551
5. 358.77805501498045
,将x = x % 10
简化为x %= 10
。但是我无法全神贯注于这两个部分:
x = x + 1
如果可能的话,它看起来像什么?
x += 1
?这似乎...如果没错,那么会令人困惑。
答案 0 :(得分:1)
表达式=
在C中不合法。赋值运算符的结果(无论是x += 1;
x %= 10;
还是复合赋值运算符之一)都不是左值。松散地说,这意味着它不能出现在作业的左侧。
该声明必须分为两部分:
(x += 1) %= 10
顺便说一句,Date Google.Close Amazon.Close Google.Return Amazon.Return
2017-08-22 924.69 966.90 NA NA
2017-08-23 927.00 958.00 0.002498132 -0.0092046993
2017-08-24 921.28 952.45 -0.006170411 -0.0057933069
2017-08-25 915.89 945.26 -0.005850571 -0.0075489547
2017-08-28 913.81 946.02 -0.002271034 0.0008040222
2017-08-29 921.29 954.06 0.008185487 0.0084987398
date<-gas$Date
amzcl<-gas$Amazon.Close
googcl<-gas$Google.Close
rtn_date <-gas$Date[2:253]
amzR<-gas$Amazon.Return[2:253]
googR<-gas$Google.Return[2:253]
plot(date, amzcl, ylim=c(900, 2000), type="l", pch=16,
xlab="Amazon Stock Price by Year",
ylab="Amazon Closing Price")
axis(1,date,format(date,format="%y"))
在C ++中有效。
答案 1 :(得分:0)
请尝试使用x += 1; x %= 10;
作为替代方法,它可以工作,但它并不等同于第一个表达式。您不能将两者都包装在一个表达式中[1],
x op= expression;
表示
x = x op (expression); /* look at the parenthesis */
,这将强制首先对表达式求值。唯一的情况是
x = (x op1 a) op2 b;
如果操作符是关联的并且表达式可以转换为:可以转换为op-assign操作
x = x op1 (a op2 b);
(或者如果op2
的优先级高于op1
,则表示评估顺序如上所述),然后
x op1= a op2 b;
将是可能的。
x = x + a + b; ==> x += a + b; /* this implies a different order of evaluation */
x = x + a * b; ==> x += a * b;
x = x + a % b; ==> x += a % b; /* % has higher precedence than + */
注意[1] :可以,但是使用另一个运算符,
逗号运算符,可以将其转换为x += 1, x %= 10;