[算术运算符]
说明
乘法是四种主要算术运算之一。运算符*
(星号)对两个操作数进行运算以生成乘积。
用法
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大神的英文原创作品 *。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。