*(乗算)

Last revision:2024/05/21

名称

*(乗算)

説明

乗算は四則演算の一つである。演算子*(アスタリスク)は、二つのオペランドの積を計算する。

書式

product = operand1 * operand2;

引数

product変数。利用できるデータ型: int, float, double, byte, short, long。
operand1変数か定数。利用できるデータ型: int, float, double, byte, short, long。
operand2変数か定数。利用できるデータ型: int, float, double, byte, short, long。

使用例

1
2
3
4
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

注意

  1. 乗算を行った後の結果が、データ型が格納可能な値より大きい場合はオーバーフローが発生する。
  2. オペランドの一つがfloatかdoubleの場合は、浮動小数点計算が使われる。
  3. オペランドがfloatdoubleの場合でも、結果を格納する変数が整数型の場合、整数部分だけが格納され、小数部分は失われる。
1
2
3
4
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

参照

オリジナルのページ

https://docs.arduino.cc/language-reference/en/structure/arithmetic-operators/multiplication/

最終更新日

July 22, 2026

inserted by FC2 system