How To Use C Operator Explain Briefly Details With Example

How To Use C Operator Explain Briefly Details With Example
How To Use C Operator Explain Briefly Details With Example

    How To Use C Operator Explain Briefly Details With Example

    Operator C Language: A C Language is a Special operator that is a mathematical operation performed in the C language. Operator Can be used to solve the mathematical operation Perform logically. Operators have used variables and data calculation.

    Types Operator in C Language

    1. Arithmetic Operator
    2. Relational Operator
    3. Logical Operator 
    4. Assignment operator
    5. Bitwise Operator
    6. Increment operator
    7. Decrement Operator
    8. Conditional Operator

    Arithmetic Operator: A arithmetic operation is a used mathematical operation performed. It is many operations performed like additionsubtraction, multiplication, and division.

    Important Same Other Languages Operator

    👉C++ Operators 

    👉Java Operators 

    👉Python Operators


    Arithmetic operator in C Language

    Addition:a+b or 10+10=20
    Here a is operands value (+) Addition is operator and b is operands. It can be used for additional operations performed.

    Subtraction:a-b or 20-10=10
    Here a is operands value (-) Subtraction sign is operator and b is operands. It can be used as Subtraction operations performed.

    Multiplication: a*b or 10*10=100
    Here a is operands value (*) Multiplication sign is operator and b is operands. It can be used Multiplication operations performed.

    Division:a/b or 10/5=2
    Here a is operands value (/) Division sign operator and b is operands. It can be used for Division operations performed.

    Modulas:a%b or 10%3=1
    Here a is operands value (%) Modules sign operator and b is operands. It can be used Modules operations performed.

    Arithmetic Operator  Table

    Sign.           Operation.         Example
    (+)              Addition                    (a+b)
    (-)               Subtraction              (a-b)  
    (*)              Multiplication         (a*b)
    (/)               Division                     (a/b)
    (%)            Modules                    (a%b)


    How To Use Arithmetic Operator in C?

    #include<stdio.h>


    int main()


    {


    int x=35


    int y=6;


    int add,sub,multi,div,mod;


    add=x+y;


    sub=x-y;


    multi=x*y


    div=x/y;


    mod=x%y;


    printf("Addition:%d\n",add); 


    printf("Subtraction:%d\n",sub); 


    printf("Multiplication:%d\n",multi);

     

    printf("Division:%d\n",div); 


    printf("Modulus:%d\n",mod);


    }
     


    *****OUTPUT*****


    Addition:41


    Subtraction:29


    Multiplication:210


    Division:5.8333333


    Modulus:5


    Relational Operator in C Language

    Relational Operator: Relational operators are used in the comparison of the two operands. It can be using equal operands and condition check in this operator. Relational operator very most and useful operator.

    Relational Operator  Table

    Sign.      Operation.         Example
    (==)           Equal To              (a+b)
    (!=)           Not Equal To       (a-b)   
    (>)            Greater Than       (a*b)
    (<)             Less Than           (a/b)
    (>=)   Grater than Or Equal  (a%b)
    (<=)   Less Than Or  Equal    (a%b)


    How To Use Relational Operator in C?

    #include<stdio.h>


    int main()


    {


    int a=10;


    int b=10;


    if(a==b)


    {


    printf("value of a and b are equal\n");


    }


    if(a!=100)


    {


    printf("value not equal to\n");


    }


    if(a>5)


    {


    printf("value a is grater than 5\n");


    }


    if(a<50)


    {


    printf("value a is less than 50\n");


    }


    if(a>=10)


    {


    printf("value a is grater than or equal to 10\n");


    }


    if(a<=10)


    {


    printf("value a is less than or equal to 10\n");


    }


    }


    *****OUTPUT*****


    value of a and b are equal


    value not equal to


    value a is greater than 5


    value a is less than 50


    value a is greater than or equal to 10


    value a is less than or equal to 10


    Logical Operator in C Language

    Logical Operators: C Language provides three logical operators. logical Operator tests more than one condition to make decisions.

    Types of Logical Operator

    1.&& AND Operator 
    2.|| OR Operator 
    3.!  NOT Operator 

    1. AND Operator can be used decisions are two values.AND Operator two values are True AND Operator return True. But two values are anyone False AND Operator return False.

    2. OR operator performs a logical condition on two expressions. if or Operator can be two expressions are True OR Operator return true. But any of the expressions are False OR Operator return True.

    3. NOT operator is very easy Operator. it can be used condition are True NOT Operator returns False and condition are False NOT Operator returns True.

    How To Use Logical AND Operator in C?

    #include<stdio.h>

    #include<string.h>

    #include<conio.h>

    int main()

    {

    char user[100]="icoderweb";

    char pass[100]="123456";

    char user1[100];

    char pass1[100];

    printf("Enter username:");

    scanf("%s",&user1);

    printf("Enter password:");

    scanf("%s",&pass1);

    if(strcmp(user,user1)==0&&strcmp(pass,pass1)==0)

    {

    printf("Login successfuly");

    }

    else

    {
    printf("invalid username and password");

    }

    }

    *****OUTPUT*****


    Enter username:icoderweb


    Enter password:123456


    Login successfully


    How To Use Logical OR Operator?

    #include<stdio.h>

    #include<string.h>

    #include<conio.h>

    int main()

    {

    char user[100]="icoderweb";

    char pass[100]="123456";

    char user1[100];

    char pass1[100];

    printf("Enter username:");

    scanf("%s",&user1);

    printf("Enter password:");

    scanf("%s",&pass1);

    if(strcmp(user,user1)==0||strcmp(pass,pass1)==0)

    {

    printf("Login successfuly");

    }

    else

    {

    printf("invalid username and password");

    }

    }

    *****OUTPUT*****


    Enter username:icoderweb


    Enter password:123653265


    Login successfully


    How To Use NOT Operator in  C?

    #include <stdio.h>

    int main()

    {

    int a=100;

    printf("Not Operator value:%d\n",!(a!=100));

    return 0;

    }

    *****OUTPUT*****

    Not Operator value:1


    Increment Operator in  C Language

    Increment Operator:Increment Operators are useful operators generally used.like++x and x++ means x=x+1.

    pre-increment first add one to the operand and then the result is assigned to the variable on the left.

    post-increment first assigns the value to the variable on the left and then increments the operand.

    How To Use Increment Operator in C? 

    #include<stdio.h>

    int main()

    {

    int a=5;

    int b=10;

    printf("pre-increment operator:%d\n",++a);

    printf("post-increment operator:%d\n",b+1);

    }

    *****OUTPUT*****


    pre-increment operator:6


    post-increment operator:11


    Decrement Operator in  C Language

    Decrement Operator: A Decrement Operator has used the decrease the value. like --x and x--.

    Pre-decrement first less one to the operands and then the result is assigned to the variable on the left.

    Post-decrement first assigns the value to the variables on the left and then decrements the operands.

    How To Use Decrement Operator in C?

    #include<stdio.h>

    int main()

    {

    int a=5;

    int b=10;

    printf("pre-decrement operator:%d\n",--a);

    printf("post-decrement operator:%d\n",b-1);

    }

    *****OUTPUT*****

    pre-decrement operator:4


    post-decrement operator:9


    Bitwise Operator in  C Language

    Bitwise Operator: A Bitwise operator is an operation performed on the data bit level.

    the bitwise operator is also shifted bit right to left.
    Note: Bitwise operators are not allowed to float and double.

    Bitwise Operator  Table

    Sign.        Operation.         Example
    (&)           Bitwise AND         (a&b)
    (|)             Bitwise OR             (a|b)  
    (<<)         Bitwise LEFT        (a<<2)
    (>>)        Bitwise RIGHT      (a>>2)


    How To Use Bitwise Operator in C?

    #include <stdio.h>

    int main()

    {

    int y=10, x=30;

    printf("Bitwise AND Operator:%d\n", x&y);

    printf("Bitwise OR Operator:%d\n", x|y);

    printf("Right shift by:%d\n",x>>2);

    printf("Left shift by:%d\n",x<<2);

    return 0;

    }

    *****OUTPUT*****

    Bitwise AND Operator:10


    Bitwise OR Operator:30


    Right shift by:7


    Left shift by:120


    Assignment Operator  Table

    Sign.        Operation        Example
    (=)            a=b                      (a=b)
    (+=)        a+=b                      (a=a+b)   
    (-=)         a-=b                       (a=a-b)
    (*=)        a*=b                      (a=a*b)
    (/=)          a/=b                      (a=a/b)
    (%=)       a%=b                 (a=a%b)


    How To Use Assignment Operator in C?

    #include <stdio.h>


    int main()


    {


    int a=10,b=5;


    a+=b;


    printf("Assignment Addition:%d\n",a);


    int a1=10,b1=5;


    a1-=b1;


    printf("Assignment Subtraction:%d\n",a1);


    int a2=10,b2=5;


    a2*=b2;


    printf("Assignment Multiplication:%d\n",a2);


    int a3=10,b3=5;


    a3/=b3;


    printf("Assignment Division:%d\n",a3);


    int a4=16,b4=5;


    a4%=b4;


    printf("Assignment Moduls:%d",a4);   


    return 0;


    }


    *****OUTPUT*****


    Assignment Addition:15


    Assignment Subtraction:5


    Assignment Multiplication:50


    Assignment Division:2


    Assignment Moduls:1


    Tags

    Post a Comment

    0 Comments
    * Please Don't Spam Here. All the Comments are Reviewed by Admin.