View stunning SlideShares in full-screen with the new iOS app!Introducing SlideShare for AndroidExplore all your favorite topics in the SlideShare appGet the SlideShare app to Save for Later — even offline
View stunning SlideShares in full-screen with the new Android app!View stunning SlideShares in full-screen with the new iOS app!
An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C language program to operate on data and variables.
3.
‘ C’ Has A Set Of Operators Which Can Be Classified As
All the basic arithmetic operations can be carried out in C. All the operators have almost the same meaning as in other languages. Both unary and binary operations are available in C language . Unary operations operate on a single operand, therefore the number 5 when operated by unary – will have the value –5.
Often it is required to compare the relationship between operands and bring out a decision and program accordingly. This is when the relational operator come into picture. C supports the following relational operators.
40.
Operator Meaning < less than <= less than or equal to > greater than >= greater than or equal to == equal to != not equal to
A simple relational expression contains only one relational operator and takes the following form.
42.
exp1 relational operator exp2 Where exp1 and exp2 are expressions, which may be simple constants, variables or combination of them. Given below are some examples of relational expressions .
This operator is used to evaluate 2 conditions. If both the expressions to the left and to the right of the logical operator is true then the whole compound expression is true. Example
The logical not operator takes single expression and evaluates to true if the expression is false and evaluates to false if the expression is true. In other words it just reverses the value of the expression. For example
The Assignment Operator evaluates an expression on the right of the expression and substitutes it to the value or variable on the left of the expression.
53.
The commonly used shorthand assignment operators are as follows:
54.
Statement with simple assignment operator Statement with shorthand operator a = a + 1 a += 1 a = a – 1 a -= 1 a = a * (n+1) a *= (n+1) a = a / (n+1) a /= (n+1) a = a % b a %= b
The increment (++) and decrement (--) operators simply add 1 or subtract 1 from a variable and return the value of that variable. These are unary operators meaning they work on only one operand.
There are two ways to use these operators – prefix or postfix, that means you can put the operator in front of the variable like ++a or behind the variable like b-- respectively.
57.
In prefix notation the variable is incremented or decremented first, then the new value is returned.
58.
In postfix notation the variable's original value is returned, and the addition or subtraction happens later.
if ( Condition ) return Expression1; else return Expression2;
The Condition expression must evaluate to true or false. If condition is true Expression1 is evaluated and its value is returned. If Condition is false Expression2 is evaluated and its value is returned.
Bitwise operators work on the bits stored in integral types. They work similar to the logical operators except that instead of working on true and false values they work with ones and zeroes. There are several bitwise operators available:
64.
Symbol and their Meaning: ~ Complement & And | Or ^ Exclusive-Or << Left shift >> Right shift
The complement operator is a unary operator. The other bitwise operators are binary, taking two arguments. Every bit that is 1 in the operand is 0 in the result.
66.
The exclusive-OR (XOR), it performs same as logical OR operator:
The result is 1 only when either X is equal to 1 or Y is equal to 1, but not when both X and Y are equal to 1.
Views
Actions
Embeds 0
Report content