Postfix operators are operators that are suffixed to an expression.

operand`++;`

This causes the value of theoperandto be returned. After the result is obtained, the value of the operand is incremented by 1.

operand`--;`

This is the same but the value of the operand is decremented by 1.

Examples:

`int joe=3;`

joe++;

The value of `joe`

is now 4.

`printf("%i",joe++);`

This outputs the number 4. The value of `joe`

is now 5.

Prefix operators are operators that are prefixed to an expression.

`++`

operand`;`

This causes the value of the operand to be incremented by 1. Its new value is then returned.

`--`

operand`;`

This is the same but the value of the operand is decremented by 1.

`!`

operand

Returns the logical NOT operation on the operand. A true operand returns false, a false operand returns true. Also known as the bang operand.

`~`

operand

Returns the compliment of the operand. The returned value is the operand with its bits reversed (1's become 0's, 0's become 1's).

Examples:

`int bart=7;`

printf("%i",--bart);

This outputs the number 6. The value of bart is now 6.

`int lisa=1;`

printf("%i",!lisa);

This outputs 0 (false).

There are several normal operators which return the result defined for each:

expression1`+`

expression

The result of this is the sum of the two expressions.

expression1`-`

expression2

The result of this is the value ofexpression2subtracted fromexpression1.

expression1`*`

expression2

The result of this is the value ofexpression1multiplied byexpression2.

expression1`/`

expression2

The result of this is the value ofexpression1divided byexpression2.

expression1`%`

expression2

The result of this is the value of the remainder after dividingexpression1byexpression2. Also called the modulo operator.

expression1`&`

expression2

Returns a bitwise AND operation done onexpression1andexpression2. The result is a value the same size as the expressions with its bits modified using the following rules: Both bits must be 1 (on) to result in 1 (on), otherwise the result is 0 (off).

e1 e2 Result 0 0 0 0 1 0 1 0 0 1 1 1

expression1`|`

expression2

Returns a bitwise OR operation done onexpression1andexpression2. The result is a value the same size as the expressions with its bits modified using the following rules: Both bits must be 0 (off) to result in 0 (off), otherwise the result is 1 (on).

e1 e2 Result 0 0 0 0 1 1 1 0 1 1 1 1

expression1`^`

expression2

Returns a bitwise XOR operation done onexpression1andexpression2. The result is a value the same size as the expressions with its bits modified using the following rules: If both bits are the same, then the result is 0 (off), otherwise the result is 1 (on).

e1 e2 Result 0 0 0 0 1 1 1 0 1 1 1 0

expression1`>>`

shift_value

Returnsexpression1with its bits shifted to the right by theshift_value. The leftmost bits are replaced with zeros if the value is nonnegative or unsigned. This result is the integer part ofexpression1divided by 2 raised to the power ofshift_value. Ifexpression1is signed, then the result is implementation specific.

expression1`<<`

shift_value

Returnsexpression1with its bits shifted to the left by theshift_value. The rightmost bits are replaced with zeros. This result is the value ofexpression1multiplied by the value of 2 raised to the power ofshift_value. Ifexpression1is signed, then the result is implementation specific.

The boolean operators return either 1 (true) or 0 (false).

expression1`&&`

expression2

Returns the logical AND operation ofexpression1andexpression2. The result is 1 (true) if both expressions are true, otherwise the result is 0 (false).

e1 e2 Result 0 0 0 0 1 0 1 0 0 1 1 1

expression1`||`

expression2

Returns the logical OR operation ofexpression1andexpression2. The result is 0 (false) if bother expressions are false, otherwise the result is 1 (true).

e1 e2 Result 0 0 0 0 1 1 1 0 1 1 1 1

expression1`<`

expression2

Returns 1 (true) ifexpression1is less thanexpression2, otherwise the result is 0 (false).

expression1`>`

expression2

Returns 1 (true) ifexpression1is greater thanexpression2, otherwise the result is 0 (false).

expression1`<=`

expression2

Returns 1 (true) ifexpression1is less than or equal toexpression2, otherwise the result is 0 (false).

expression1`>=`

expression2

Returns 1 (true) ifexpression1is greater than or equal toexpression2, otherwise the result is 0 (false).

expression1`==`

expression2

Returns 1 (true) ifexpression1is equal toexpression2, otherwise the result is 0 (false).

expression1`!=`

expression2

Returns 1 (true) ifexpression1 is not equal toexpression2, otherwise the result is 0 (false).

An assignment operator stores the value of the right expression into the left expression.

expression1`=`

expression2

The value ofexpression2is stored inexpression1.

expression1`*=`

expression2

The value ofexpression1timesexpression2is stored inexpression1.

expression1`/=`

expression2

The value ofexpression1divided byexpression2is stored inexpression1.

expression1`%=`

expression2

The value of the remainder ofexpression1divided byexpression2is stored inexpression1.

expression1`+=`

expression2

The value ofexpression1plusexpression2is stored inexpression1.

expression1`-=`

expression2

The value ofexpression1minusexpression2is stored inexpression1.

expression1`<<=`

shift_value

The value ofexpression1's bits are shifted to the left byshift_valueand stored inexpression1.

expression1`>>=`

shift_value

The value ofexpression1's bits are shifted to the right byshift_valueand stored inexpression1.

expression1`&=`

expression2

The value of the bitwise AND ofexpression1andexpression2is stored inexpression1.

e1 e2 Result 0 0 0 0 1 0 1 0 0 1 1 1

expression1`^=`

expression2

The value of the bitwise XOR ofexpression1andexpression2is stored inexpression1.

e1 e2 Result 0 0 0 0 1 1 1 0 1 1 1 0

expression1`|=`

expression2

The value of the bitwise OR ofexpression1andexpression2is stored inexpression1.

e1 e2 Result 0 0 0 0 1 1 1 0 1 1 1 1

The operators have a set order of precedence during evaluation. Items encapsulated in parenthesis are evaluated first and have the highest precedence. The following chart shows the order of precedence with the items at the top having highest precedence.

Operator | Name |
---|---|

! | Logical NOT. Bang. |

++ -- | Increment and decrement operators. |

* / % | Multiplicative operators. |

+ - | Additive operators. |

<< >> | Shift operators. |

< > <= >= | Inequality comparators. |

== != | Equality comparators |

& | Bitwise AND. |

^ | Bitwise XOR. |

| | Bitwise OR. |

&& | Logical AND. |

|| | Logical OR. |

?: | Conditional. |

= op= |
Assignment. |

Examples:

`17 * 5 + !(1+1) && 0`

Evaluates to 0 (false).

`5+7<4`

Evaluates to 1 (true).

`a<b<c`

Same as (a<b)<c.