BeerSong Last Statement



I don’t understand the output of the last statement:

printf(“Put a bottle in the recycling, %d empty bottles in the bin.\n”, numberOfBottles);

I would think that once the numberOfBottles == 0, it would bypass these commands:

printf("%d bottles of beer on the wall. %d bottles of beer.\n",
numberOfBottles, numberOfBottles);
int oneFewer = numberOfBottles -1;
printf(“Take one down, passit around, %d bottles of beer on the wall.\n”,oneFewer);
singTheSong(oneFewer); // This function calls itself!

and then print: “Put a bottle in the recycling, 0 empty bottles in the bin.” (since the numberOfBottles is now ==0

I don’t quite understand how it would go on and print the from 1 - 99…

Perhaps I’m not following the flow of the execution… I tried to figure out the last part using the frames in the debugger setting the breakpoint in several places, but couldn’t figure out…

So far I’m really enjoying the book i’m just a little frustrated I got stuck here… :frowning:

I would really appreciate if anyone could help me understand the part where I’m stuck…

Thank You!!!


Hi Pipeline,

I was really stumped by this as well, but think I finally got it thanks to this thread:


The posts by Calcien (linked above) and the one below it by tu71586 were what really helped me understand it.


I was stumped by this too. Thanks for the info., it really helped the penny drop