arithmetic_operator

unary + and -

Forces the integer to be positive or negative respectively.

“The unary + operator does nothing”

int j = 5;
int i = +j; /* does nothing but can be used for style */
int i = -j;/* think (-1) * j, it flips the sign bit */

binary /

integer /

int i = 1;
int j = 2;
float k;
x = i/j; // truncates, hence x = 0

/ 0 is undefined. in c89 divsion with a -ve can be rounded up or down. in c99 division with a -ve is always rounded towards 0.

%, datatype acceptable, % 0, and % -n -ve numbers

the modulus operator % only accepts integers. For floats see fmod. % 0 is undefined. In c89 negative operands depend on the implementation. In c99 i % j has the same sign as i

operator precedence

Highest: + - (unary) * / % Lowest: + - (binary)

Operators like the binary operators are left associative (implied grouping is left first then right) i - j - k is equivalent to (i - j) - k In contrast, unary operators are right associative- + i is equivalent to - (+)

standard

wood

related

backlinks