Operators in C

Arithmetic Operators
OperatorDescriptionExample
+To add two numeric valuesa+b
-Used for subtractiona-b
*To multiply two numeric valuesa*b
/Used for divisiona/b
% (Modulo operator)To compute the remainder of a division operationa%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
OperatorUseDescription
>a>bExpression return true if a is greater than b
>=a>=bTrue if a is greater than or equal to b
<a
True if a is less than b
<=a<=bTrue if a is less than or equal to b
==a==bTrue if a is equal to b
!=a==bTrue 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
OperatorMeaningDescription
&&Logical ANDCombine to conditional expressions, and will return true if both conditional expressions are true otherwise it will return false.
||Logical ORCombine 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.

Previous
Next

0 comments:

Design by The Blogger Templates The Blog Full of Games

© CourseZone
2008 - 2010 All Rights Reserved.