C Operators

Operators

Operators is an symbols which are perform of logical or mathematical operation in c programming. operator are classified into following category.

C Operators Types
  • Arithmetic Operator
  • Logical Operators
  • Relational Operators
  • Assignment Operators
  • Bitwise Operators

Arithmetic Operator

Arithmetic operators are used to perform mathematical operation of two operands. using of these operator we can easily to calculate like addition, subtraction,multiplication, division. and also can solve mathematical equation.

Operator Name
+ Addition( plus sign)
- Subtract (minus sign)
* multiplication (* symbol)
/ Divide
% remainder operator

Example

/* 
  Example of Arithmetic Operator
*/
/*Header file*/
#include <stdio.h>

int main(){

    int a=10,b=5,resutl;

    //add
    resutl=a+b;
    printf("Addition    [%d + %d] : %d\n",a,b,resutl);
    //subtract
    resutl=a-b;
    printf("subtraction [%d - %d] : %d\n",a,b,resutl);
    //multiply
    resutl=a*b;
    printf("multiply    [%d * %d] : %d\n",a,b,resutl);
    //divide
    resutl=a/b;
    printf("division    [%d / %d] : %d\n",a,b,resutl);
    //modules
    resutl=a%b;
    printf("remainder   [%d %% %d] : %d\n",a,b,resutl);
    return 0;
}

Output

Addition    [10 + 5] : 15
subtraction [10 - 5] : 5
multiply    [10 * 5] : 50
division    [10 / 5] : 2
remainder   [10 % 5] : 0

Logical Operators

logical operator are used to compare simply based on multiple condition. this condition are based on operand. operand and logical operator are combine together and make a decision expression. this expression are returns boolean value. this boolean value are (1,0) True and False . if expression is valid then its True otherwise False. Here given of three logical operators.

Operator Name
&& Logical AND operator.
|| Logical OR Operator
! Logical NOT Operator

Relational Operators

relational operator are used to compare two values. this is work on two operand or two values so it also called binary operator.result of relational operator is boolean value( True and false). here given six relational operator.

Operator Name
> greater than
< less than
== equal to equal to
>= greater than equal to
<= less than equal to
!= Not equal to

Assignment Operators

assignment operators are used to initialize and assign new value to variables. there are denoted as (=) equal sign.

Operator Meaning
= equal
*= Multiply and assign
+= Add and assign
/= Divide and assign
-= Subtract and assign
%= calculate remainder and assign

Bitwise Operators

Bitwise Operator are work in bit level. this bits are represented in from of binary numbers (0,1).perform all operation in (CPU) is work on bit-level. here given six Bitwise operators.

Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
~ Bitwise complement
>> Shift Right
<< Shift left

© 2019, regularcodes.com, All rights reserved