Answer SL47

Out of Scope

The scope of sum is the block statement of the for loop, so it is out of scope in the return statement. The program will not compile.

Also, inside the loop is not correct because sum would be initialized to zero for each iteration:


 
int sumInts( int limit )
{
  int j;

  for ( j=1; j<=limit; j++ )
  {
    int sum = 0;  
    sum += j;
  }
    
  return sum;
}


Back to Puzzle Home