Earn while u Learn

Tips tweaks hacks on computer with C C++ VB tutorials and ways to earn money online

ad

Operators in C

The symbol which is used to represent a particular operation on some data is called an operator.The various types of operators are:
1. Arithmetic operator :    operator                             action
                                               -                                  subtraction
                                               +                                    addition
                                               *                                   multiplication
                                               /                                      division
        EX:   n/2+3;
                x*2-6
2. Increment Decrement operator : The two increment and decrement operators are  ++ and  --  . The ++ operator adds 1 to the operand and the -- operator subtracts 1 from the operand.
   Ex:   int x=99;
           x++;
                         result  99+1=100.

3. Rational Operators :           Operator                    Action
                                                     >                         greater than
                                                     >=                      greater than equal to
                                                     <                         less than
                                                     <=                      less than equal to
                                                     = =                     equal to ( it is used for equal to sign in C)
                                                      !=                      not equal to
4. Logical operator :                operator                       action
                                                     &&                              and
                                                      ||                                  or
                                                      !                                  not
5. Conditional operator or ternary operator : syntax  exp 1? exp2 : exp 3
            i.e. if exp 1 is true the value returned will be exp 2  else the value returned will be exp 3.
  Ex     main()
            {
           int x,y;
           printf("enter a no.");
          scanf("%d",&x);
           y=(x>11? 10:12);
           printf("%d",y);
           getch();
            }
result: y will store 10 if value of x is greater than 11 or the value o f y will be 12.

0 comments:

Sign in / Join

Labels