Inner variable shadows outer variable : Variable Scope « Language « C Tutorial






#include <stdio.h>
int main(void)
{
  int count = 0;                                
  do
  {
    int count = 0;                
    ++count;                      
    printf("\ncount = %d ", count);
  }
  while( ++count <= 8 );  /* This works with outer count */

  /* this is outer */
  printf("\ncount = %d\n", count);
  return 0;
}
count = 1
     count = 1
     count = 1
     count = 1
     count = 1
     count = 1
     count = 1
     count = 1
     count = 1
     count = 9








1.8.Variable Scope
1.8.1.Scope of variables
1.8.2.Inner variable shadows outer variable