[算術運算符]
說明
乘法是四種主要算術運算之一。運算符*
(星號)對兩個操作數進行運算以生成乘積。
用法
product = operand1 * operand2;
參數
product
: 多變的。允許的數據類型: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 50 after this statement is executed
注意事項和警告
-
如果結果大於可以存儲在數據類型中的結果,則乘法運算可能會溢出。
-
如果其中一個數字(操作數)是 float 類型或 double 類型,則浮點數學將用於計算。
-
如果操作數是浮點/雙精度數據類型,並且存儲乘積的變量是整數,則隻存儲整數部分,丟失數字的小數部分。
float a = 5.5;
float b = 6.6;
int c = 0;
c = a * b; // the variable 'c' stores a value of 36 only as opposed to the expected product of 36.3
相關用法
- 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 WiFi101 - WiFi.subnetMask()用法及代碼示例
注:本文由純淨天空篩選整理自arduino.cc大神的英文原創作品 *。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。