Another slight change.
/* --- sumVersion8.c --- */
#include <stdio.h>
int sumInts( int limit )
{
static int sum = 0;
int j;
for ( j=1; j<=limit; j++ )
{
sum += j;
}
return sum;
}
void main()
{
int sum = sumInts( 10 );
printf( "sum of 1..10: %d\n", sum );
sum = sumInts( 5 );
printf( "sum of 1..5: %d\n", sum );
}
The variable sum
used in the
functionis now block scope but static.
What does the program output?