Tuesday 1 June 2021

OPERATOR IN C

 

Operators:
An operator is the symbol that specify the operation or activity to be perform.
Example:
                 C language is very reach in operator the operators in cand be classified based on_
1. The number operant used by operator.
2. The type of operation being perform.

1. The number operant used by operator:
                A  mathematical expression consists of number and variable joined by operator such as +,-,*, the operator are classified in 3 category on operates.
1. Unary operator [a *, a/, a++]

2. Binary operator [a+b, 2/3, s*3]
3. Ternary operator [?;] (a>b ? a:b)


1.Unary operator:   [a*, a/, a++]:
(a) Post: first use the value then update the              value.             

(b) Pre: first update the value then use the                value.

(a) Post:   1. Post increment (a++)
                   2.  Post decrement (a--)

Example:
                 If a=5
                  a++ then a=6
                  a--  then a=4

(b) Pre:    1. Pre increment (++a)
                   2.  Pre decrement (--a)
Example:
                 If a=5
                  ++a then a=6
                  --a  then a=4
PROGRAM⤵️

(I).   #include<stdio.h>
        #include<conio.h>
           void main()
           {
               clrscr();
               int a=6, b=7;
               a++;
               ++b;
               --a;
               --b;
               b--;
               printf("%d%d",a,b); //  a=6,  b=6;
               getch();
           }
      Output➡️. 66
       
(II)     #include<stdio.h>
          #include<conio.h>
              void main()
              {
                   clrscr();
                   int  a=6, b=7;
                   a=a+++b++;
                   b=b+++a++;
                   printf("%d%d",a,b);
                   getch();
             }

      Output➡️. 1418

  

2.  Binary  operator: [a+b, 2/3, s*3]:            
                     Binary operators act upon a two operands to produce a new value (0 or 1).

Syntax for binary operator is:
              operand1     operator      operand2

 

3. Ternary operator: [?:] (a>b ? a:b):
                      If any operator is used  on three operands or variable is known as Ternary Operator. It can be represented with ? : . It is also called as conditional operator.

It helps to think of the ternary operator as a shorthand way or writing an if-else statement. Programmers use the ternary operator for decision making in place of longer if and else conditional statements.

Syntax for ternary operator is:
             (condition)?(statement 1):(statement 2);
Example:
  (a>b)?printf('a is greater):printf("b is greater");

2. The type of operation being perform:
                                             
1.   Arithmetic operator [+,-,*,%,/]
2.  Assignment operator [*=,-=,+=,/=,%=]
3.   Increment increase or decrease [++,--]
4.   Relational operator [<=,>=,==]
5.   Logical operator
6.   Conditional operator [<,>,<=,>=,=][?,;]
7.   Bitwise operator [~,<<,>>,&,!,^]
8.   Special operator

1. Arithmetic operator:[+,-,*,%,/]:
                        The operator that are used to perform arithmetic operation such as +,-,*,/,% are called arithmetic operator can be classified in two types of this on the number of operants.

 (I).  Arithmetic binary operator
(II).  Arithmetic Unary operator

2. Assignment operator:[*=,-=,+=,/=,%=]:
                           An operator which is used to copy the the data and result of an expression in a memory location is called assignment operator the assignment operator is donated by '=' sign
Syntax:
             Variable=variable

Shorthand operator:
                     We can also used to shorthand and rotation for assignment operator such as-
Shorthand        shorthand.            Meaning
operator           expression

+ =                         a+=10                    a=a+10
- =                          a-=10                    a=a- 10
* =                          a* =5                     a=a* 5
/ =                          a/=?                      a=0/?

3. Increment or decrement operator:[++,--]:
                                         These operator are very compact and powerful operators available in C language. These two operator are Unary operator use single operants are classified into two categories.



PROGRAM for increment operator⤵️
  
    #include<stdio.h>
    #include<conio.h>
      void main()
       {
         clrscr();
         int x=3;
         x++; //x=x+1. Post-increment(x++)
         printf("%d",x);
         ++x; //x=x+1. Pre-increment(++x)
         printf("%d",x);
         getch();
       }
    Output➡️. 45

PROGRAM for decrement operator⤵️:
            
            #include<stdio.h>
            #include<conio.h>
              void main()
               {
                   clrscr();
                   int x=3;
                   x--;  //x=x-1.    Post decrement
                   printf("%d",x);
                   --x; //x=x-1.     Pre decrement
                   printf("%d",x);
                   getch();
               }
       Output➡️. 21 


4. Relational operator:[<=,>=,==]:
                          The relational operator also called comparison operator are used to compare two Operants they are used to find the relationship between two operants are constant or variable are expressions. The relationship between these two operants in 0 or 1.
>.      Greater than
<.      Less than
>=.    Great than equal to
<=.    Less than equal to
!=.     Not equal to
==.    Equal to

5.  Logical operator:
                     As we have logic gates such as  AND,OR,NOT. Whose output is 1 or 0 be also have logical operators. After evaluation expression consisting of a logical operators result in either true or false. Such expression are called logical expressions.
1.   [&]       AND   (Binary operator)
2.   [||]      OR      (Binary operator)
3.   [!]         NOT   (Unary operator)


1. Logical AND:
                   The result of logical AND operation denoted by '&&' is true if AND only if both the operants are evaluated to true if one of the operant is evaluated is false then the result is false.                              
If (a==b && b==c)     
 equilateral triangle


2. Logical OR: 
                    The result of logical OR operation denoted by '||'  is true if and only if one of the operants is evaluated is true if both the Operants are evaluated to false.


3. Logical NOT:
                    Logical NOT denoted by '!' can be true or false. The result is true if the Operants is false and the result is false if the Operants is true.
                    

6. Conditional operator:
                             The conditional operator also called ternary operator as the name index an operator that operant and three Operants called ternary operator that is [?,|]
Syntax:
                  (Example 1? Example 2; Example 3;)
Example:⤵️
                 
                #include<stdio.h>
                #include<conio.h>
                   void main();
                    {
                        int a,b,c;
                        scanf("%d%d",&a,&b);
                        c=a>b?a:b;
                        printf("%d",c);
                        getch();
                    }
            Output➡️Writing a big or a small condition will display a large condition in the output. Ex: 10
                     20
On display. 20                  


7. Bitwise operator:
                     The data is stored in the memory in term of binary digit,s. That is '0' or '1' some time it may be necessary manipulate these bites. The operators that are to manipulate the bits are called bitwise operators.

Operator.                          Description

~.                         Bitwise Identical [Negative]
<<                        Left shift
>>                        Right shift 
&                         Bitwise AND
!                           Bitwise OR
^                          Bitwise x-or


8. Special operator:
                   Below are some of the special operators that the C programming language offers.

Operator            Discription

    &.                This is used to get the
                        address Of the variable.
                        Example: &a will give address 
                        of a.
        
    *.                 This is used as pointer to a 
                        variable.
                        Example: *a where, *is 
                        pointer to the variable a.

Sizeof().         This gives the size of the
                        variable.
                        Example: size of (char) will
                        give as 1.
         
EXAMPLE PROGRAM FOR & AND * OPERATORS IN C:
      In this program, "&" symbol is used to get the address of the variable and "*" symbol is used to get the value of the variable that the pointer is pointing to.
   
#include<stdio.h>
#include<conio.h>
  void main()
  {
     int *ptr,  q;
     q = 50; /*address of q is assigned of ptr*/               
     ptr = &q; /*display q's value using variable*/       printf("%d", *ptr);
     getch();
  }

Output➡️50

EXAMPLE PROGRAM FOR SIZEOF() OPERATOR IN C:
               sizeof() operator is used to find the memory space allocated for each C data types.
 
Program ๐Ÿ“บ

Output➡️ storage size for int data type:2
                  storage size for int data type:1
                  storage size for int data type:4
                  storage size for int data type:8
HINDI TRANSLATION:➡️ เคนिंเคฆी เค…เคจुเคตाเคฆ ⤵️๐Ÿ‘‡๐Ÿ‘‡
 
 Operators:
       เคเค• operator เคตเคน เคช्เคฐเคคीเค•(symbol) เคนै เคœो เคจिเคท्เคชाเคฆिเคค(perform) เค•िเค เคœाเคจे เคตाเคฒे Operation เคฏा activity เค•ो เคจिเคฐ्เคฆिเคท्เคŸ(specify) เค•เคฐเคคा เคนै।

เค‰เคฆाเคนเคฐเคฃ:
             Operator เคฎें C language เคฌเคนुเคค เคชเคนुंเคš เคฎें เคนै Operator เค•ो 2 เค†เคงाเคฐों เคชเคฐ เคตเคฐ्เค—ीเค•ृเคค เค•िเคฏा เคœा เคธเค•เคคा เคนै
 1. Operator เคฆ्เคตाเคฐा เค‰เคชเคฏोเค— เค•िเคฏा เคœाเคจे เคตाเคฒा เคจ number          operator
 2. เคœिเคธ เคช्เคฐเค•ाเคฐ เค•ा Operation เค•िเคฏा เคœा เคฐเคนा เคนै।

1. Operator เคฆ्เคตाเคฐा เค‰เคชเคฏोเค— เค•िเคฏा เคœाเคจे เคตाเคฒा number operator:
                 เคเค• mathematical เคต्เคฏंเคœเค•(expression)  เคฎें number เค”เคฐ variable เคถाเคฎिเคฒ เคนोเคคे เคนैं เคœो Operator เคธे เคœुเคก़े เคนोเคคे เคนैं เคœैเคธे +,-,*, Operator เค•ो operate เค•เคฐเคจे เคชเคฐ 3 เคถ्เคฐेเคฃी เคฎें เคตเคฐ्เค—ीเค•ृเคค เค•िเคฏा เคœाเคคा เคนै।

1. Unary operator [a *, a/, a++]

2. Binary operator [a+b, 2/3, s*3]
3. Ternary operator [?;] (a>b ? a:b)


1.Unary operator: [a*, a/, a++]:
(a) Post:   เคชเคนเคฒे value เค•ा เค‰เคชเคฏोเค— เค•เคฐें เคซिเคฐ value เค•ो                         update เค•เคฐें।         
(b) Pre: เคชเคนเคฒे value เค•ो update เค•เคฐें เคซिเคฐ value เค•ा                      เค‰เคชเคฏोเค— เค•เคฐें।
(a) Post: 1. Post increment (a++)
                   2. Post decrement (a--)

เค‰เคฆाเคนเคฐเคฃ:
              If a=5
                  ++a then a=6
                  --a then a=4

PROGRAM⤵️


(I). #include<stdio.h>
        #include<conio.h>
           void main()
           {
               clrscr();
               int a=6, b=7;
               a++;
               ++b;
               --a;
               --b;
               b--;
               printf("%d%d",a,b); // a=6, b=6;
               getch();
           }
      Output➡️. 66
       
(II) #include<stdio.h>
          #include<conio.h>
              void main()
              {
                   clrscr();
                   int a=6, b=7;
                   a=a+++b++;
                   b=b+++a++;
                   printf("%d%d",a,b);
                   getch();
             }

      Output➡️. 1418


2. Binary operator: [a+b, 2/3, s*3]:      
                       Binary operator เคเค• เคจเคฏा value (0 เคฏा 1) เค‰เคค्เคชเคจ्เคจ เค•เคฐเคจे เค•े เคฒिเค เคฆो Operants เคชเคฐ เค•ाเคฐ्เคฏ เค•เคฐเคคे เคนैं।
Syntax for binary operator is:
              operand1 operator operand2


3. Ternary operator: [?:] (a>b ? a:b):
                      เคฏเคฆि เคคीเคจ operants เคฏा variables เคชเคฐ เค•िเคธी เคญी operator เค•ा เค‰เคชเคฏोเค— เค•िเคฏा เคœाเคคा เคนै เคคो Ternary Operator เค•े เคฐूเคช เคฎें เคœाเคจा เคœाเคคा เคนै। เค‡เคธเค•े เคธाเคฅ เคช्เคฐเคคिเคจिเคงिเคค्เคต(represented) เค•िเคฏा เคœा เคธเค•เคคा เคนै? : . เค‡เคธे conditional operator เคญी เค•เคนा เคœाเคคा เคนै।

 เคฏเคน ternary operator เค•ो shorthand เคคเคฐीเค•े เค•े เคฐूเคช เคฎें เคธोเคšเคจे เคฏा if-statement เคฒिเค–เคจे เคฎें เคฎเคฆเคฆ เค•เคฐเคคा เคนै। Programmer ternary operator เค•ा เค‰เคชเคฏोเค— เคฒंเคฌे เคธเคฎเคฏ เคคเค• เค”เคฐ เค…เคจ्เคฏ conditional statement เค•े เคธ्เคฅाเคจ เคชเคฐ เคจिเคฐ्เคฃเคฏ เคฒेเคจे เค•े เคฒिเค เค•เคฐเคคे เคนैं।

Syntax for ternary operator is:
             (condition)?(statement 1):(statement 2);
Example:
  (a>b)?printf('a is greater):printf("b is greater"

2. The type of operation being perform:

1. Arithmetic operator [+,-,*,%,/]
2. Assignment operator [*=,-=,+=,/=,%=]
3. Increment increase or decrease [++,--]
4. Relational operator [<=,>=,==]
5. Logical operator
6. Conditional operator [<,>,<=,>=,=][?,;]
7. Bitwise operator [~,<<,>>,&,!,^]
8. Special operator

1. Arithmetic operator:[+,-,*,%,/]:
                           เคตเคน Operator เคœो arithmetic operation เคœैเคธे +,-,*,/,% เค•ो เค•เคฐเคจे เค•े เคฒिเค เคช्เคฐเคฏोเค— เค•िเคฏा เคœाเคคा เคนै, automatic operator เค•เคนเคฒाเคคे เคนैं, เคธंเค•्เคฐिเคฏाเค“ं(Operants) เค•ी เคธंเค–्เคฏाเคฏा(number) เค•े เค†เคงाเคฐ เคชเคฐ เค‡เคธे เคฆो เคช्เคฐเค•ाเคฐों เคฎें เคตเคฐ्เค—ीเค•ृเคค เค•िเคฏा เคœा เคธเค•เคคा เคนै।
 (I).  Arithmetic binary operator
(II).  Arithmetic Unary operator      


2. Assignment operator:[*=,-=,+=,/=,%=]:
                             เคเค• Operator เคœिเคธเค•ा เค‰เคชเคฏोเค— memory location เคฎें data เค”เคฐ เค…เคญिเคต्เคฏเค•्เคคि เค•े เคชเคฐिเคฃाเคฎ เค•ी เคช्เคฐเคคिเคฒिเคชि เคฌเคจाเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै, assignment operator เค•เคนเคฒाเคคा เคนै assignment operator เค•ो '=' เคšिเคน्เคจ เคฆ्เคตाเคฐा เคฆाเคจ เค•िเคฏा เคœाเคคा เคนै  
  Syntax:

             Variable=variable

Shorthand operator:

                      เคนเคฎ assignment operator เค•े เคฒिเค shorthand เค”เคฐ rotation เค•े เคฒिเค เคญी เค‡เคธ्เคคेเคฎाเคฒ เค•เคฐ เคธเค•เคคे เคนैं เคœैเคธे-

Shorthand        shorthand.            Meaning
operator           expression

+ =                         a+=10                    a=a+10
- =                          a-=10                    a=a- 10
* =                          a* =5                     a=a* 5
/ =                          a/=?                      a=0/?


3. Increment or decrement operator:[++,--]:

                                  เคฏे operator C language เคฎें เค‰เคชเคฒเคฌ्เคง เคฌเคนुเคค เคนी เค•ॉเคฎ्เคชैเค•्เคŸ เค”เคฐ เคถเค•्เคคिเคถाเคฒी operator เคนैं। เคฏे เคฆो operator unary operator เค‰เคชเคฏोเค— เคเค•เคฒ operators เค•ो เคฆो เคถ्เคฐेเคฃिเคฏों เคฎें เคตเคฐ्เค—ीเค•ृเคค เค•िเคฏा เค—เคฏा เคนै।


 Increment operator เค•े เคฒिเค program:⤵️

             #include<stdio.h>

               #include<conio.h>
                 void main()
                  {
                     clrscr();
                     int x=3;
                     x++; //x=x+1.    Post increment (x++)
                     printf("%d",x);
                     ++x; //x=x+1.    Pre increment (++x)
                     printf("%d",x);
                     getch();
                  }
      Output➡️. 45

Decrement operator เค•े เคฒिเค program:⤵️

            #include<stdio.h>

            #include<conio.h>
              void main()
               {
                   clrscr();
                   int x=3;
                   x--;  //x=x-1.    Post decrement
                   printf("%d",x);
                   --x; //x=x-1.     Pre decrement
                   printf("%d",x);
                   getch();
               }
       Output➡️. 21 


4. Relational operator:[<=,>=,==]:

                         Relational operator เคœिเคธे comparison operator เคญी เค•เคนा เคœाเคคा เคนै, เค•ा เค‰เคชเคฏोเค— เคฆो operators เค•ी เคคुเคฒเคจा เค•เคฐเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै, เคœिเคจเค•ा เค‰เคชเคฏोเค— เคฆो operators เค•े เคฌीเคš เคธंเคฌंเคง เค–ोเคœเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै เคœो เคธ्เคฅिเคฐ เคนोเคคे เคนैं เคฏा variable expression เคนोเคคे เคนैं। เค‡เคจ เคฆो operators เค•े เคฌीเคš 0 เคฏा 1 เคฎें เคธंเคฌंเคง।

>.      Greater than
<.      Less than
>=.    Great than equal to
<=.    Less than equal to
!=.     Not equal to
==.    Equal to


5. Logical operator:

                    เคœैเคธा เค•ि เคนเคฎाเคฐे เคชाเคธ logic gates เคนैं เคœैเคธे เค•ि  AND,OR,NOT। เคœिเคธเค•ा output 1 เคฏा 0 เคนो เค‰เคธเค•े เคชाเคธ logical Operators เคญी เคนों। เคฎूเคฒ्เคฏांเค•เคจ เค•े เคฌाเคฆ logical Operators เคธे เคฏुเค•्เคค เค…เคญिเคต्เคฏเค•्เคคि เค•ा เคชเคฐिเคฃाเคฎ เคธเคนी เคฏा เค—เคฒเคค เคนोเคคा เคนै। เคเคธे เคต्เคฏंเคœเค• Logical expression เค•เคนเคฒाเคคे เคนैं।

1. [&]   AND (Binary operator)

2. [||] OR (Binary operator)

3. [!]    NOT (Unary operator)


1. Logical AND:

                    Logical AND  operation เค•ा เคชเคฐिเคฃाเคฎ '&&' เคฆ्เคตाเคฐा เคจिเคฐूเคชिเคค เคธเคค्เคฏ เคนै เคฏเคฆि เค”เคฐ เค•ेเคตเคฒ เคฏเคฆि เคฆोเคจों Operators  เค•ा เคฎूเคฒ्เคฏांเค•เคจ เคธเคค्เคฏ เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै เคฏเคฆि เค•िเคธी เคเค• เค•ा เคฎूเคฒ्เคฏांเค•เคจ เค—เคฒเคค เคนै เคคो เคชเคฐिเคฃाเคฎ เค—เคฒเคค เคนै।

If (a==b && b==c)


                                                   equilateral triangle



2. Logical OR: 
                    Logical OR operation เค•ा เคชเคฐिเคฃाเคฎ '||' เคฆ्เคตाเคฐा เคฆเคฐ्เคถाเคฏा เค—เคฏा เคนै เคฏเคน เคธเคš เคนै เค…เค—เคฐ OR เค•ेเคตเคฒ เค…เค—เคฐ เคฆोเคจों Operators เคฎें เคธे เคเค• เค•ा เคฎूเคฒ्เคฏांเค•เคจ เค•िเคฏा เคœाเคคा เคนै เคคो เคฏเคน เคธเคš เคนै เคฏเคฆि เคฆोเคจों Operators เค•ा เคฎूเคฒ्เคฏांเค•เคจ เค—เคฒเคค เคนै।

3. Logical NOT: 
                    Logical NOT '!' เคฆ्เคตाเคฐा เคจिเคฐूเคชिเคค เคธเคš เคฏा เคूเค  เคนो เคธเค•เคคा เคนै। เคฏเคฆि operator เค—เคฒเคค เคนै เคคो เคชเคฐिเคฃाเคฎ เคธเคค्เคฏ เคนै เค”เคฐ เคฏเคฆि operator เคธเคค्เคฏ เคนै เคคो เคชเคฐिเคฃाเคฎ เค—เคฒเคค เคนै।

6. Conditional operator:

                                 Conditional Operator เค•ो ternary operator เค•ो เคจाเคฎ index เค•े เคฐूเคช เคฎें เคญी เค•เคนा เคœाเคคा เคนै, เคเค• operator เคœो operator เค”เคฐ เคคीเคจ operators เค•ो ternary operator เค•เคนा เคœाเคคा เคนै [?,|]

Syntax:
                  (Example 1? Example 2; Example 3;)
Example:⤵️
                 
                #include<stdio.h>
                #include<conio.h>
                   void main();
                    {
                        int a,b,c;
                        scanf("%d%d",&a,&b);
                        c=a>b?a:b;
                        printf("%d",c);
                        getch();
                    }
            Output➡️เคฌเคก़ी เคฏा เค›ोเคŸी เค•ंเคกीเคถเคจ เคฒिเค–เคจे เคธे เค†เค‰เคŸเคชुเคŸ เคฎें เคฌเคก़ी เค•ंเคกीเคถเคจ เคช्เคฐเคฆเคฐ्เคถिเคค เคนोเค—ी।Ex:10
                                              20
                         On display. 20 



7. Bitwise operator:

                    Data เค•ो memory  เคฎें binary digit, s เค•े เคŸเคฐ्เคฎ เคฎें store เค•िเคฏा เคœाเคคा เคนै। เคฏाเคจी '0' เคฏा '1' เค•เคญी-เค•เคญी เค‡เคจ เค•ाเคŸเคจे เคฎें เคนेเคฐเคซेเคฐ เค•เคฐเคจा เค†เคตเคถ्เคฏเค• เคนो เคธเค•เคคा เคนै। bits เคฎें เคนेเคฐเคซेเคฐ เค•เคฐเคจे เคตाเคฒेे operators เค•ो bitwise operator เค•เคนा เคœाเคคा เคนै।

Operator.                Description


~.                               Bitwise Identical [Negative]

<<                              Left shift

>>                              Right shift 

&                               Bitwise AND

!                                Bitwise OR

^                               Bitwise x-or


8. Special operator:

                   เคจीเคšे เค•ुเค› เคตिเคถेเคท operator เคฆिเค เค—เค เคนैं เคœो C programming language เคช्เคฐเคฆाเคจ เค•เคฐเคคा เคนै।

Operator                        Discription


&.                         This is used to get the 

                             address Of the variable.

                             Example: &a will give address 

                             of a.

          

*.                            This is used as pointer to a 

                               variable.

                               Example: *a where, *is 

                               pointer to the variable a.


Sizeof().               This gives the size of the

                               variable.

                               Example: size of (char) will

                               give as 1.


EXAMPLE PROGRAM FOR & AND * OPERATORS IN C:

         #include<stdio.h>

         #include<conio.h>
            void main()
            {
               int *ptr,  q;
               q = 50;            /*address of q is assigned                                            of ptr*/                                     
               ptr = &q;        /*display q's value using                                              variable*/
               printf("%d", *ptr);
               getch();
            }

Output➡️50

EXAMPLE PROGRAM FOR SIZEOF() OPERATOR IN C:
                        sizeof() operator เค•ा เค‰เคชเคฏोเค— เคช्เคฐเคค्เคฏेเค• C data type เค•े เคฒिเค เค†เคตंเคŸिเคค เคฎेเคฎोเคฐी เคธ्เคชेเคธ เค•ो เค–ोเคœเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै।

Output ➡️ storage size for int data type:2
                   storage size for int data type:1
                   storage size for int data type:4
                   storage size for int data type:8

OPERATOR IN C

  Operators : An operator is the symbol that specify the operation or activity to be perform. Example :                  C language is ve...