OPERATORS
Arithmetic (+,-,*,/,%)
Relational (<,>,<=,>=,==,!=)
Logical (&&,||,!)
Bitwise (&,|)
Assignment (=)
Compound assignment(+=,*=,-=,/=,%=,&=,|=)
Shift (right shift >>, left shift <<)
Example for Arithmetic operator
Add_Two_Numbers (a,b) /* Add a and b */
int a,b;
{
int c;
c = a + b;
printf ("%d",c);
}
Example for Relational operator
myfunction (a,b) /* breaking out of functions early */
int a,b;
{
while (a < b)
{
if (a > b)
{
return (b);
}
a = a + 1;
}
}
Example for logical operator
if ((i > 2) && (i < 4))
{
printf ("i is three");
}
OPERATORS(Contd.)
Increment and Decrement Operators
++ Increment operator
-- Decrement Operator
k++ or k-- (Post-increment/decrement)
k = 5;
x = k++; // sets x to 5, then increments k to 6
++k or --k (Pre-increment/decrement)
k = 5;
x = ++k; // increments k to 6 and then sets to the
resulting value, i.e., to 6
OPERATORS(Contd.)
Increment and Decrement Operators
++ Increment operator
-- Decrement Operator
k++ or k-- (Post-increment/decrement)
k = 5;
x = k++; // sets x to 5, then increments k to 6
++k or --k (Pre-increment/decrement)
k = 5;
x = ++k; // increments k to 6 and then sets to the
resulting value, i.e., to 6

Operators in C

  • 1.
    OPERATORS Arithmetic (+,-,*,/,%) Relational (<,>,<=,>=,==,!=) Logical(&&,||,!) Bitwise (&,|) Assignment (=) Compound assignment(+=,*=,-=,/=,%=,&=,|=) Shift (right shift >>, left shift <<)
  • 2.
    Example for Arithmeticoperator Add_Two_Numbers (a,b) /* Add a and b */ int a,b; { int c; c = a + b; printf ("%d",c); }
  • 3.
    Example for Relationaloperator myfunction (a,b) /* breaking out of functions early */ int a,b; { while (a < b) { if (a > b) { return (b); } a = a + 1; } }
  • 4.
    Example for logicaloperator if ((i > 2) && (i < 4)) { printf ("i is three"); }
  • 5.
    OPERATORS(Contd.) Increment and DecrementOperators ++ Increment operator -- Decrement Operator k++ or k-- (Post-increment/decrement) k = 5; x = k++; // sets x to 5, then increments k to 6 ++k or --k (Pre-increment/decrement) k = 5; x = ++k; // increments k to 6 and then sets to the resulting value, i.e., to 6
  • 6.
    OPERATORS(Contd.) Increment and DecrementOperators ++ Increment operator -- Decrement Operator k++ or k-- (Post-increment/decrement) k = 5; x = k++; // sets x to 5, then increments k to 6 ++k or --k (Pre-increment/decrement) k = 5; x = ++k; // increments k to 6 and then sets to the resulting value, i.e., to 6