Operators are used with operands to build expressions. For example the following is an expression containing two operands and one oprator.
4 + 5
The following list of operators is probably not complete but does highlight the common operators and a few of the outrageous ones....
C contains the following operator groups.
The order (precedence) that operators are evaluated can be seen here.
+ - / * % modulo -- Decrement (post and pre) ++ Increment (post and pre)
Assigns a value to a variable. If the variable is a string constant, modifying the variable may cause segment fault since it is modifying the code segement wehre the litteral value may be stored. These can also perform an arithmetic operation on the lvalue and assign the result to the lvalue. So what does this mean in English? Here is an example: counter = counter + 1; can be reduced to counter += 1;
Here is the full set.
= Simple assignment without any operations *= Multiply /= Divide. %= Modulus. += add. -= Subtract. <<= left shift. >>= Right shift. &= Bitwise AND. ^= bitwise exclusive OR (XOR). |= bitwise inclusive OR.
== Equal to != Not equal to >= Greater than or equal to < Less than > Greater than <= Less than or equal to && Logical AND || Logical OR ! Logical NOT
& AND (Binary operator) | inclusive OR ^ exclusive OR << shift left. C ++ use of << >> shift right. C ++ use of >> ~ one's complement
sizeof() size of objects and data types. strlen may also be of interest. & Address of (Unary operator) * pointer (Unary operator) ? Conditional expressions : Conditional expressions , Series operator.
Read about :: >> and << in the world of C++ here!
Top | Master Index | Keywords | Functions |