Search This Blog

Thursday, 14 March 2013

Other Operators in c


Assignment Operator:
This Operator is used to assign the Left hand side value or expression to the right hand side variable.
For Example:
Int b=10; ------------>1
Int x=3,y=4,z;--------------->2
Z=x+y+2;
 In the above example  ‘b’ is  a variable created and is assigned (stored) with the value 10.
Note: In right hand side always should be a variable .and left hand side may be value , constant or expression.

Conditional  or Ternary Operator(?:)
Syntax:
Expr1?Expr2 : Expr3

 Here Operator ? :  is called as ternary  Operator , which is mainly used to evaluate the Conditions.
First Exp1 is Evaluated ,if it is true then Expr2 is Evaluated otherwise Expr3 is evaluated and the result is assigned to the variable on the LHS used with the Assignment Operator.

Size Of Operator:
Operator which is used to find the number of bytes  required to Store that operand variable. This Operator  returns the number of bytes  occupied by the operand.
SYNTAX
Size of(data type or variable name);

Eg : Sizeof(int)  …………………> returns  2;
        Sizeof(float)………………..> returns 4;

Double d;
Int x;
X= sizeof(d);
It returns 8 which stores into x;
Comma Operator(,)
This operator is used to separate Expressions.
Eg a=10 ; b=5; c=a*b;
Above statements can be written as c=(a=10,b=5, a*b);


0 comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Hostgator Discount Code