Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

*: multiplying numeric values

The binary * operator multiplies arithmetic values. The result and overflow rules depend on the operand types after the usual conversions.

Version: C23

Syntax

left * right

In a * b, the asterisk denotes multiplication when it has an operand on each side. Different arithmetic types undergo the usual arithmetic conversions. 3 * 4 produces 12, while 3 * 0.5 produces the floating-point result 1.5.

Multiplication has higher precedence than addition: 2 + 3 * 4 produces 14. Parentheses change grouping: (2 + 3) * 4 produces 20. Left associativity does not determine the order of operand side effects; avoid combining those effects in one expression.

Signed integer overflow is undefined behavior. An unsigned result is reduced modulo one more than the maximum value of its type. Floating-point calculations can involve rounding. Dereferencing with *p and declaring a pointer with int *p are different uses of the same symbol.

Examples

#include <stdio.h>

int main(void) {
    printf("%d %d %.1f\n", 2 + 3 * 4, (2 + 3) * 4, 3 * 0.5);
    return 0;
}

Result

14 20 1.5

Sources