Operators in C

Overview of the C Operators

The C operators fall into the following categories:
  • Postfix operators, which follow a single operand only.
  • Unary prefix operators, which precede with a single operand.
  • Binary operators, which take two operands and perform a variety of logical and arithmetic operations.
  • The conditional operator (a ternary operator), which takes three operands and evaluates either the second or third expression, depending on the evaluation of the first expression only.
  • Assignment operators, which only assign a value to a variable.
  • The comma operator, which gives guarantees left-to-right evaluation of comma-separated expressions
To create more complex expressions,variables and constants can be used in conjunction with C operators. The following tables describes different operators available in c
Operator  Example  Description/Meaning 
()   f()   Function call 
[]   a[10]   Array reference 
->   a  ="">a> Structure and union member selection 
.   s.a   Structure and union member selection 
+ [unary]  +a   Value of a 
- [unary]  -a   Negative of a 
* [unary]  *a   Reference to object at address a 
& [unary]  &a   Address of a 
~a   One's complement of a 
++ [prefix]  ++a   The value of a after increment 
++ [postfix]  a++   The value of a before increment 
- - [prefix]  -a   The value of a after decrement 
- - [postfix]  a-   The value of a before decrement 
sizeof   sizeof (t1)   Size in bytes of object with type t1 
sizeof   sizeof e   Size in bytes of object having the type of expression e 
+ [binary]
- [binary]
* [binary]
/ % 
a + b
a - b
a * b
a / b
a % b  
a plus b
a minus b
a times b
a divided by b
Remainder of a/b 
>>
<< 
a >> b
a << b  
a, right-shifted b bits
a, left-shifted b bits 
<
>
<=
>=
==
!=  
a < b
a > b
a <= b
a >= b
a == b
a != b  
1 if a < b; 0 otherwise
1 if a > b; 0 otherwise
1 if a <= b; 0 otherwise
1 if a >= b; 0 otherwise
1 if a equal to b; 0 otherwise
1 if a not equal to b; 0 otherwise 
& [binary]
|
a & b
a | b
a ^ b  
Bitwise AND of a and b
Bitwise OR of a and b
Bitwise XOR (exclusive OR) of a and b 
&&
||
!  
a && b
a || b
!a  
Logical AND of a and b (yields 0 or 1)
Logical OR of a and b (yields 0 or 1)
Logical NOT of a (yields 0 or 1) 
?:  a ? e1 : e2   Expression e1 if a is nonzero;
Expression e2 if a is zero 
=
+=
-=
*=
/=
%=
>>=
<<=
&=
|=
^=
a = b
a += b
a -= b
a *= b
a /= b
a %= b
a >>= b
a <<= b
a &= b
a |= b
a ^= b
e1,e2  
a, after b is assigned to it
a plus b (assigned to a)
a minus b (assigned to a)
a times b (assigned to a)
a divided by b (assigned to a)
Remainder of a/b (assigned to a)
a, right-shifted b bits (assigned to a)
a, left-shifted b bits (assigned to a)
a AND b (assigned to a)
a OR b (assigned to a)
a XOR b (assigned to a)
e2 (e1 evaluated first) 


Precedence of C Operators

Category  Operator  Associativity 
Postfix  () [] -> . ++ - -   Left to right 
Unary  + - ! ~ ++ - - (type) * & sizeof   Right to left 
Multiplicative   * / %  Left to right 
Additive   + -  Left to right 
Shift   << >>  Left to right 
Relational   < <= > >=  Left to right 
Equality   == !=  Left to right 
Bitwise AND  Left to right 
Bitwise XOR  Left to right 
Bitwise OR  Left to right 
Logical AND  &&  Left to right 
Logical OR  ||  Left to right 
Conditional  ?:  Right to left 
Assignment  = += -= *= /= %= >>= <<= &= ^= |=  Right to left 
Comma  Left to right 

#vpsinghrajput

Author & Editor

Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.

0 comments:

Post a Comment