*

[Arithmetic Operators]

説明

乗算は四則演算の一つです。*(アスタリスク)演算子は2つの被演算子を演算して積を求めます。

構文

product = operand1 * operand2;

媒介変数

product: 変数。許可されるデータ型: intfloatdoublebyteshortlong.
operand1: 変数または定数。許可されるデータ型: intfloatdoublebyteshortlong.
operand2: 変数または定数。許可されるデータ型: intfloatdoublebyteshortlong.

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. 数値 (オペランド) の 1 つが float 型または double 型の場合、計算には浮動小数点演算が使用されます。
  3. オペランドが 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

Language Reference Home

86Duinoリファレンスのテキストは、Arduinoリファレンスを改変したもので、Creative Commons Attribution-ShareAlike 3.0ライセンスに基づいてライセンスされています。リファレンス内のコードサンプルはパブリックドメインとして公開されています。

上部へスクロール