專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> Arduino >> 瀏覽文章

Arduino復(fù)合運(yùn)算符

作者:huqin   來(lái)源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2014年04月03日   【字體:

+= , -= , *= , /=
Description描述
Perform a mathematical operation on a variable with another constant or variable. The += (et al) operators are just a convenient shorthand for the expanded syntax, listed below.
對(duì)一個(gè)變量和另一個(gè)參數(shù)或變量完成一個(gè)數(shù)學(xué)運(yùn)算。+=(以及其他)可以縮短語(yǔ)法長(zhǎng)度。

 

Syntax語(yǔ)法
x += y; // equivalent to the expression x = x + y; // 等價(jià)于 x = x + y;
x -= y; // equivalent to the expression x = x - y; // 等價(jià)于 x = x - y;
x *= y; // equivalent to the expression x = x * y; // 等價(jià)于 x = x * y;
x /= y; // equivalent to the expression x = x / y; // 等價(jià)于 x = x / y;

Parameters參數(shù)
x: any variable type
x:任何變量類型

y: any variable type or constant
y:任何變量類型或常數(shù)

Examples范例
x = 2;
x += 4; // x now contains 6 // x現(xiàn)在為6
x -= 3; // x now contains 3 // x現(xiàn)在為3
x *= 10; // x now contains 30 // x現(xiàn)在為30
x /= 2; // x now contains 15 // x現(xiàn)在為15


Syntax語(yǔ)法
x++; // increment x by one and returns the old value of x
// 將x的值加1并返回原來(lái)的x的值。 ++x; // increment x by one and returns the new value of x // 將x的值加1并返回現(xiàn)在的x的值。
x-- ; // decrement x by one and returns the old value of x // 將x的值減1并返回原來(lái)的x的值。
--x ; // decrement x by one and returns the new value of x // 將x的值減1并返回現(xiàn)在的x的值。

Parameters參數(shù)
x: an integer or long (possibly unsigned)
x:一個(gè)整數(shù)或長(zhǎng)整數(shù)(可以無(wú)符號(hào))

Returns返回
The original or newly incremented / decremented value of the variable.
返回變量原始值或增加/消耗后的新值。

Examples范例
x = 2;
y = ++x; // x now contains 3, y contains 3 // x現(xiàn)在為3,y為3
y = x--; // x contains 2 again, y still contains 3 // x現(xiàn)在仍然為2,y將為3

關(guān)閉窗口

相關(guān)文章