Wednesday, September 2, 2009

c programming operator using tips

1.      Precedence decides which operator should be perform first

         Example:-
          P = 6 / 2 + 4 * 3

            (Operator /  and  * enjoy same priority  so it is evaluated from  Left to Right)

          P = 6 / 2  + 4 * 3   [ Operation  of   / ]

          P = 3 +  4 * 3        [ Operation of *]
     
          P = 3 + 12            [ Operation of +]
  
          P =  15
      2. Associative determine the order of evaluation

3. Left to Right  & Right to left are two associative rules used when two or more than two same  operators enjoy the same Priority.
4. There is no operators in C to find out the value of “ A  raised to  power B”.
5. comma ( ,) operator is the lowest priority form the group of 45 operator.
6. parenthesis ( ), [], . and -> having highest priority from group of 45 operators .
7. Sizeof( ) is an operator and a keyword which look like function.
8. Modules ( %) is an operator that works with only integral type.
 Example:-
      Float x ;
     X = 10.0 % 3 ;
     Printf(“ %f ”, x);  //( wrong approach )
 Int x ;
X = 10 / 3 ;
Printf ( “%d”, x) ;  // right approach

9. C does not allow “culprits”  such as ** ,//
  example :
int a=4;
a**;
printf(“%d”, a);

10. unary operator (++,--) Can apply to variable not to constants.
11.unary operator plus (+) is dummy operator.
    Int a=6;
   +a;
printf (“%d”,a);

12. some time ternary operator (?:) replace the conditional if statement.

Like  example:-
Int a=6;
If(a>5)
 Printf(“hello”);
Else
Printf(“hi”);

(a>=5)?printf(“hello”):printf(“hi”);

13.comma and parenthesis are twin brothers.

Example :

While ( (P=getch() )!= EOF)
While ( p=getch() ,!=EOF )
14. Return Keyword cannot be used with ternary operator (?:)
  void main()
  {
 int p=5;
p>65540? Return1 : return 0;
}

15.the bit wise operator work with only integer and character .

16. continuous triple plus (+++) is allowed but not more or less.
  For example:
   Int a=3 b;
    B = a+++5; // means b = a ++ + 5  which is 8

17.      More then one + is allow in same statement but space matter a lot between operator .
18.      ## operator helps to concatenate between tokens

#define m (x) printf(“yes %d”, a##x)
void main()
{
int a1=32;
int a2=30;
m(1);
m(2);
}
19.      Turboc used many punctuation know as separators like (), [],.. etc.
20.      caste operator is an operator which is a signal (force) to compiler to convert one caste to other caste .

         example :-  float x; x =  (float) 5/2;
 21. all operators in C can be overload in c++ but except ?: , .* :: etc



 
      

No comments:

Blog List