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

12 comments:

  1. Very perfect information sir, it will improve my knowledge. I really like it. I appreciate it heartily, dear sir

    ReplyDelete
  2. If we talk of appearance of the page it is really awesome, moreover description of the facts is really good

    ReplyDelete
  3. I was seeking for some technical computer knowledge on likewise pages but nowhere could I find. And now I think my search ends here because I hope I'll get what I need. Thank you sir

    ReplyDelete
    Replies
    1. This is your nobility sir that you come to my blog and read it
      Thank you

      Delete

OPERATOR IN C

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