Operators In C

An operator is a symbol which is used to perform some operation on variables, operands and with the constant.

Types of Operators:

  1. Arithmetic Operator
  2. Assignment Operator
  3. Increment Operator
  4. Decrement Operator
  5. Relational Operator
  6. Comma Operator
  7. Sizeof Operator
  • Arithmetic Operator: This operator is used to perform the numeric calculation. And these operators are addition(+), subtraction(-), multiplication(*), division(/).

   Unary – Unary Arithmetic Operator requires only one operand +,-,++,– etc.

   Binary- This Arithmetic Operator requires two operands and its operator are           +,-,*,/ and %(modulus).

  • Assignment Operator: Any value can be stored in a variable by using the assignment operator. It is denoted by(=).

           eg:  –   int sum=x+y+z;

  • Increment and decrement Operator: The unary operator ++,– is used as increment and decrement operator.  The increment operator increases the value by 1 and the decrement operator decreases the value by 1
  •  Pre-Increment and Post Increment: First increase then the print is Pre-increment. First print then increase is post-increment. Similarly for decrement.

         A simple program to understand this concept:  

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int i;
i=i+1;
i++;
i+=1;  // i=i+1
i+=2;  // i=i+2
i*=2; // i = i*2

cout << "enter any number" ;
cin >> i;         //5

cout << i << endl;      // 5

cout << ++i << endl;    // 6

cout << i++ << endl;    // 6

cout << i << endl; // 7

cout << --i << endl;  // 6

cout << i-- << endl; // 6

cout << i << endl;  // 5

getch();
}
  • Relational Operator: This operator is used to compare the value of two expressions.

        eg: (b>a)&&(c>b)

  • Conditional Operator: It is also known as the ternary operator because it requires three expressions as operand (? , :).

         eg: exp1?exp2:exp3

  • Comma Operator: Comma Operator is used to permitting different expression to be appear in a situation where only one expression is used. 

          eg: for(i=1,j=2;j<=4;j<=10;j++)

 

Leave a Reply