Next: Operator precedence Up: C Programming Previous: C type modifiers

Arithmetic expressions

main()

/* Calculate distance travelled */
   {
   double speed;      /* miles per hour */
   double time;       /* hours */
   double distance;   /* miles */

   speed= 26.4;
   time= 4.7;
   distance= speed*time;

   printf("Distance covered was: %lf\n",distance);
   }

Note the arithmetic expression speed*time.

Note we could have written:

   double speed, time, distance;

or

double  speed,          /* miles per hour */
        time,           /* hours */
        distance;       /* miles */

and that either of the line-by-line forms makes it easier to comment the purpose of the variable.




Next: Operator precedence Up: C Programming Previous: C type modifiers


maspjw@
Tue Sep 27 15:29:34 BST 1994