Multiplication Operator *

This page was translated by a robot.

The multiplication operator performs a multiplication of two elements. For arithmetic types, this corresponds to the mathematical multiplication of two numbers.







64
6
10
15.0
#include <stdio.h>

int main(){
  int a = 2;
  int b = 3;
  float c = 7.5f;
  printf("%d\n",  8 * 8);
  printf("%d\n",  a * b);
  printf("%d\n",  a * 5);
  printf("%f\n",  a * c);
  return 0;
}

Details

The multiplication operator expects two operands as rvalues ​​and is processed from left to right . The return value is an rvalue whose type is basically determined by the arithmetic conversion of the two operands.

The operator is allowed for arithmetic (integer and floating point) types as well as the bool type. Boolean values ​​are treated as integer values. If necessary, the operands are cast according to the rules of arithmetic conversion.

In the case of arithmetic types, the multiplication operator basically corresponds to mathematical multiplication, whereby the two operands are also referred to as factors . Due to the order of precedence of the operators, it is possible to write down a positive or negative operator directly for the two factors.


-50
15
25
int a = 5;
printf("%d\n",  10 * -a);
printf("%d\n",  a  * +3);
printf("%d\n",  -a * -a);

The multiplication operator corresponds to the direct implementation of the corresponding multiplication statement in assembler and can therefore result in an overflow or underflow for arithmetic types, which leads to a wrap-around for integer types. With floating-point types, this can result in the value infinity .


1705032704

1.000000e+20
inf
unsigned int a = 3000000000;
printf("%u\n",  a * 2);
float b = 1e20;
printf("%le\n",  b);
printf("%le\n",  b * b);