Page 39 - Programming Microcontrollers in C
P. 39

24     Chapter 1  Introduction to C

                          3. Write a program that reads the characters from an input file and
                            counts in an array the occurrences of each letter. Make the pro­
                            gram “case insensitive” by treating all upper case letters as lower
                            case.


            Operators and Expressions

                              The variables and constants discussed in the previous section are
                          classed as operands. They are values or objects that are operated
                          upon by a program. The operations that take place are specified by
                          operators. This section contains a discussion of the several opera­
                          tors.
                              Operators abound in C. All of the symbols involved in the lan­
                          guage are operators. Each has a precedence and an associativity. This
                          section is concerned with how operators and operands are put to­
                          gether to interact in a manner desired by the programmer.

            Arithmetic Operators
                              The arithmetic operators are those used to perform arithmetic
                          operations. These operators are:

                                 +
                                 -
                                 *
                                 /
                                 %
                          These operators are called binary operators because they are al­
                          ways used with two operands. These operands are placed on either
                          side of the operator. The symbol + designates arithmetic addition,
                          and the – symbol designates subtraction. The symbols * and /
                          designate multiplication and division, respectively. These opera­
                          tors are clearly different for different variable types. The compiler
                          understands these differences and creates correct code for the
                          operand types involved. The modulus operator % returns the re­
                          mainder after an integer division. The modulus operator works only
                          on integer types—-int, char, and long. It cannot be applied to
                          types float, double or long double.
   34   35   36   37   38   39   40   41   42   43   44