The variable sum
is an automatic variable,
created on the run-time stack when the block is entered
and potentially not initialized.
PS C:\Source>gcc sumVersion2.c PS C:\Source>a sum: 55 PS C:\Source>
Comments:
The answer is correct, this time. But this might be luck. In a complicated program with many automatic variables pushed and popped as the program runs, an uninitialized automatic variable might end up with unexpected values. Automatic variables should always be initialized.
Different compilers, and different settings, can affect what happens.