C Operators

In computer programming an Operator is something which performs an operation on variable or values. The operators in C can be mainly classified into:

  1. Assignment Operator
  2. Arithmetic Operators
  3. Relational Operators
  4. Logical Operators
  5. Bitwise Operator
  6. Special Operators

1. Assignment Operator

The assignment Operator = assigns the value of the expression on its right hand side to the variable on the left hand side.

Example

n = 1;	/* Assign value 1 to variable n */
p = n;  /* Assign value of variable n to variable p */

2. Arithmetic Operators

Arithmetic Operators are used to perform arithmetic operations. Arithmetic operators in C are

OperatorMeaning
+Addition
-Subtraction
*Multiplication
/Division
%Modulus
++Increment
--Decrement

Examples

/* Sum of variables b and c, and subtract by 1;assign result
to variable a */
a = b + c - 1;

/* Multiply variable m by 2 and divide by k, assign result to 
variable n */
n = 2 * m / k;

/* Modulus of d by 10 - Divide variable d by 10, assign the 
remainder value to variable c */
c = d % 10;

/* Increment the value of variable i by 1 ( i = i + 1 )*/
i++;

/* decrement the value of variable i by 1 (i = i - 1) */
i--;
Last Updated: 02-May-2013


Post a comment

Name

Your Comment

Email (We dont publish it)

Comments

Nothing yet..be the first to share wisdom.