Professional Documents
Culture Documents
Operators vary from language to language but most languages have different operators that perform similar operations.
Arithmetic Operations
Here are some fundamental arithmetic operators and how they are performed in C++. Assuming a = 6: Operation Addition Subtraction Multiplication Division Modulus (Remainder of division) Common Operator + * / % C++ Example >>> a + 2 Result: 8 >>> a - 2 Result: 4 >>> a * 2 Result: 12 >>> a / 2 Result: 3 >>> a % 2 Result: 0 or >>> a % 4 Result: 2 >>> a++ Result: 7 >>> a-Result: 5
Increment Decrement
++ --
Comparison Operations
Comparison/Relational Operators test for some kind of relationship between two values. Assuming a = 6. Operation Equal To Not Equal To Bigger Than Smaller Than Bigger or Equal To Common Operator == != > < >= C++ Example >>> a == 6 Result: TRUE >>> a != 6 Result: FALSE >>> a > 10 Result: FALSE >>> a < 10 Result: TRUE >>> a >= 3 Result: TRUE or >>> a >= 8 Result: FALSE >>> a <= 3 Result: FALSE
Smaller or Equal To
<=
Assignment Operations
Assignment operators assign values to variables. The basic assignment operator in most languages is the equals sign =. The below examples are compound assignment operators which perform an arithmetic operation and then automatically assign the result to the variable. Assuming a = 6. C++ Operator += -= *= /= %= C++ Example >>> a += 2 a == 8 >>> a -= 2 a == 4 >>> a *= 2 a == 12 >>> a /= 2 a == 3 >>> a %= 4 a == 2 Same as >>> a = a +2 >>> a = a - 2 >>> a = a * 2 >>> a = a / 2 >>> a = a % 4
Truth Tables
Truth tables are used to show every possible outcome of an operation. AND operator Condition 1 AND Condition 2 Condition 1 Condition 2 FALSE FALSE FALSE TRUE TRUE FALSE TRUE TRUE Result is TRUE when Condition 1 AND Condition 2 are both TRUE. OR operator Condition 1 OR Condition 2 Condition 1 Condition 2 FALSE FALSE FALSE TRUE TRUE FALSE TRUE TRUE Result is TRUE when Condition 1 OR Condition 2 are either TRUE.
OR operator NOT Condition 1 Condition 1 Result FALSE TRUE TRUE FALSE Result is TRUE when Condition 1 is NOT TRUE. Effectively returns the opposite value.
Sources
http://en.wikipedia.org/wiki/Boolean_algebra http://www.amazon.com/Cambridge-International-Computing-Coursebook-Examinations/dp/0521186625 http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B