title: Un-initialized double has value carried over in second call to function (Head First C Example)
body: <p>So I am teaching myself programming and I was working on the price_drinks.c program from the "Head First C" book:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdarg.h&gt;
  
  enum drink { MUDSLIDE, FUZZY_NAVEL, MONKEY_GLAND, ZOMBIE };
  
  double price(enum drink d){
      switch(d) {
      case MUDSLIDE:
      return 6.79;
      case FUZZY_NAVEL:
      return 5.31;
      case MONKEY_GLAND:
      return 4.82;
      case ZOMBIE:
      return 5.89;
      }
      return 0;
  }
  
  double total(int args, ...){
      double total;
      va_list ap;
      va_start(ap, args);
      int i;
      for(i = 0; i &lt; args; i += 1){
          enum drink d = va_arg(ap, enum drink);
          total = total + price(d);
      }
      va_end(ap);
      return total;
  }
  
  int main(){
  
      printf("Price is %.2f\n", total(2, MONKEY_GLAND, MUDSLIDE));
      printf("Price is %.2f\n", total(3, MONKEY_GLAND, MUDSLIDE, FUZZY_NAVEL));
      printf("Price is %.2f\n", total(1, ZOMBIE));
  
      return 0;
  }
  </code></pre>
  
  <p>As you can see I decided to not initialize the variable total in the function total to 0, this causes a strange error for me, the output from this program is:</p>
  
  <pre><code>$ ./a.out 
  Price is 11.61
  Price is 16.92
  Price is 22.81
  </code></pre>
  
  <p>Where the first two outputs appear to be fine, automatically setting total = 0, however the third call of the function appears to carry over the value from the previous call. I was just curious as to why that might be happening?</p>
  
  <p>I understand best practices probably dictates that you always initialize your variables, I was just being lazy and came across this strange bug.</p>