Operators in C
| Arithmetic Operators | ||
|---|---|---|
| Operator | Description | Example |
| + | To add two numeric values | a+b |
| - | Used for subtraction | a-b |
| * | To multiply two numeric values | a*b |
| / | Used for division | a/b |
| % (Modulo operator) | To compute the remainder of a division operation | a%b |
Notes
- An arithmetic operation on two integer values always yields an integer result.
- Operation between float and float yields a float result.
- Operation on integer and a float value will results a float result
- % operator cannot be used with float or double values
| Relational Operators | ||
|---|---|---|
| Operator | Use | Description |
| > | a>b | Expression return true if a is greater than b |
| >= | a>=b | True if a is greater than or equal to b |
| < | a | True if a is less than b |
| <= | a<=b | True if a is less than or equal to b |
| == | a==b | True if a is equal to b |
| != | a==b | True if a and b are not equal |
Notes
- Relational operators are comparison operators which will compare two values and will return true or false.
- Relational operators are used in conditional expressions.
- == is an relational operator to check the equality of two values, but a single = operator is assignment operator.
| Logical Operators | ||
|---|---|---|
| Operator | Meaning | Description |
| && | Logical AND | Combine to conditional expressions, and will return true if both conditional expressions are true otherwise it will return false. |
| || | Logical OR | Combine to conditional expressions, and will return false if both conditional expressions are false otherwise it will return true. |
| ! | Logical NOT | Negate a conditional expression |
Notes
- Logical AND operator is used to combine two conditions, and the whole expression that is connected by the AND (&&) operator will return only true if both conditions are true, otherwise it will return false.
- Logical OR operator is used to combine two conditions, and the whole expression that is connected by the OR (||) operator will return true if any one condition is true, otherwise it will return false.
- Logical NOT operator is used to negate the conditional value, if a condition 'CON' yields a true then !CON will return false, if condition CON is false then !CON will return true.



0 comments:
Post a Comment