Mathematical Operations
The C programming language contains the standard set of mathematical operators, add (+), subtract (-), multiply (*), divide (/), and the modulus operator (%). It is important to note that integer division truncates any fractional portion of the answer. Also the % operator cannot be applied to float or double.
+ and - operators maintain the same precedence, which is lower than the precedence of *, /, and %.
In addition C provides other operators such as the increment and decrement, ++ and -- respectively. These are unary operators; that is, operators that take only one argument. The ++ and -- operators can be applied either as a prefix operator (e.g. ++x) or postfix (e.g. x++), though there are subtle differences between the prefix and postfix operator when it comes to the return value: ++x will store x+1 and return x+1 while x++ will store x+1 but return x.
There are tables that summarize the precedence and associativity for all operators, but as a general rule you should explicitly declare the order of operations using parentheses; this can greatly enhance the clarity of the code, and diminish the chance that future changes will result in mistakes, even if the current arithmetic expression is correct.
C also provides the basic logical operators && (and), || (or), ! (not), which can be utilized for comparison and evaluation in conditional statements. Bitwise analogs of these operators exist as well (&, |, and ~ respectively). In addition, many other bitwise operators and variants of these operators with assignment exist (e.g. a += b will sum a and b, then store the result in a), though they are less frequently used or provide only marginal syntactic simplicity.
CVW material development is supported by NSF OAC awards 1854828, 2321040, 2323116 (UT Austin) and 2005506 (Indiana University)