Page 40 - 6437
P. 40

/* example of sizeof operator */
                                printf("Line 1 - Size of variable a = %d\n", sizeof(a) );

                                printf("Line 2 - Size of variable b = %d\n", sizeof(b) );
                                printf("Line 3 - Size of variable c= %d\n", sizeof(c) );



                                /* example of & and * operators */

                                ptr = &a;       /* 'ptr' now contains the address of 'a'*/
                                printf("value of a is  %d\n", a);
                                printf("*ptr is %d.\n", *ptr);




                                /* example of ternary operator */
                                a = 10;
                                b = (a == 1) ? 20: 30;

                                printf( "Value of b is %d\n", b );



                                b = (a == 10) ? 20: 30;
                                printf( "Value of b is %d\n", b );

                            }

                          When you compile and execute the above program, it produces the following result:

                                          value
                                       of a    s
                                           *ptr
                                       is 4.
                                          Valu
                                      e of b   s     0
                                          Valu
                                      e of b   s     0

                          Operators Precedence in C
                          Operator precedence determines the grouping of terms in an expression and decides how
                   an expression is evaluated. Certain operators have higher precedence than others; for example, the
                   multiplication operator has a higher precedence than the addition operator.
                          For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has a higher
                   precedence than +, so it first gets multiplied with 3*2 and then adds into 7.











                                                                                                      42
   35   36   37   38   39   40   41   42   43   44   45