[算術運算符]
說明
減法是四種主要算術運算之一。運算符-
(減號)對兩個操作數進行運算,以產生第二個與第一個的差。
用法
difference = operand1 - operand2;
參數
difference
: 多變的。允許的數據類型:int
,float
,double
,byte
,short
,long
.
operand1
: 變量或常量。允許的數據類型:int
,float
,double
,byte
,short
,long
.
operand2
: 變量或常量。允許的數據類型:int
,float
,double
,byte
,short
,long
.
示例代碼
int a = 5;
int b = 10;
int c = 0;
c = a - b; // the variable 'c' gets a value of -5 after this statement is executed
注意事項和警告
-
如果結果小於可以存儲在數據類型中的結果,則減法運算可能會溢出(例如,從值為 -32,768 的整數中減去 1 得到 32,767)。
-
如果其中一個數字(操作數)是 float 類型或 double 類型,則浮點數學將用於計算。
-
如果操作數是浮點/雙精度數據類型並且存儲差值的變量是整數,則隻存儲整數部分而丟失數字的小數部分。
float a = 5.5;
float b = 6.6;
int c = 0;
c = a - b; // the variable 'c' stores a value of -1 only as opposed to the expected difference of -1.1
相關用法
- Arduino --用法及代碼示例
- Arduino -=用法及代碼示例
- Arduino long用法及代碼示例
- Arduino Arduino_EMBRYO_2 - setLengthXY()用法及代碼示例
- Arduino ~用法及代碼示例
- Arduino ArduinoBLE - bleDevice.advertisedServiceUuidCount()用法及代碼示例
- Arduino const用法及代碼示例
- Arduino Ethernet - server.begin()用法及代碼示例
- Arduino ArduinoBLE - BLEService()用法及代碼示例
- Arduino digitalWrite()用法及代碼示例
- Arduino ArduinoBLE - bleCharacteristic.subscribe()用法及代碼示例
- Arduino Servo - attach()用法及代碼示例
- Arduino write()用法及代碼示例
- Arduino Arduino_LSM9DS1 - readGyroscope()用法及代碼示例
- Arduino ArduinoSound - FFTAnalyzer.input()用法及代碼示例
- Arduino MKRGSM - gprs.attachGPRS()用法及代碼示例
- Arduino WiFiNINA - WiFi.config()用法及代碼示例
- Arduino MKRGSM - sms.read()用法及代碼示例
- Arduino MKRNB - getCurrentCarrier()用法及代碼示例
- Arduino Scheduler - Scheduler.startLoop()用法及代碼示例
- Arduino Arduino_LSM9DS1 - magneticFieldAvailable()用法及代碼示例
- Arduino MKRWAN - available()用法及代碼示例
- Arduino ArduinoBLE - BLE.poll()用法及代碼示例
- Arduino ArduinoBLE - bleCharacteristic.hasDescriptor()用法及代碼示例
- Arduino Ethernet - EthernetUDP.parsePacket()用法及代碼示例
注:本文由純淨天空篩選整理自arduino.cc大神的英文原創作品 -。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。