Home Segments Index Top Previous Next

48: Mainline

To change the value of a variable, you use the assignment operator, =. Three assignment statements appear in the following program:

#include  
main ( ) { 
  int size_one = 600, size_two = 100, size_three = 200, sum; 
  sum = size_one;           
  sum = sum + size_two;     
  sum = sum + size_three;   
  printf ("The average number of shares traded is "); 
  printf ("%i", sum / 3); 
  printf ("\n"); 
} 
--- Result --- 
The average number of shares traded is 300 

Of course, this program is a bit awkward—the only reason to split the computation of price into three separate statements is to demonstrate that a variable can be assigned and then reassigned.