Page 50 - Programming Microcontrollers in C
P. 50

Precedence and Associativity      35

                            < <= > =>                                        left to right

                            == !=                                            left to right
                            &                                                left to right

                            ^                                                left to right
                            |                                                left to right

                            &&                                               left to right
                            ||                                               left to right

                            ?:                                               right to left
                            = += -= *= /= %= &= ^= |= <<= >>= right to left

                            ,                                                left to right
                              Note the very high precedence of the parentheses and the square
                          brackets. It is the high precedence of these operators that allows the
                          programmer to force operations that are not in line with the normal
                          precedence of the language. The second highest precedence is the
                          list of unary operators. These operators are all associated from right
                          to left.


                          EXERCISES
                          1. Which of the following words are valid names for use in a C pro­
                            gram?

                            able                       toots
                            What_day_is_it             WindowBar
                            _calloc                    8arnold
                            Hurting?                   value
                            constant                   Constant
                            sizeof                     continue
                          2. Write a program to evaluate the constant

                            ( 1.0377x107 + 3.1822x103 ) / ( 7.221x104 + 22.1x106 )
                            The answer will be 0.468162.

                          3. Write a function that raises the integer x to the power n. Name the
                            function x_to_the_n, and write a program that evaluates
                            x_to_the_n for several different values of both x and n.
   45   46   47   48   49   50   51   52   53   54   55