Variable scope: in and out a block
#include <stdio.h>
void main()
{
int c = 0; /* Declared in outer block */
do
{
int c = 0; /* This is another variable called c */
++c ; /* this applies to inner c */
printf("\n c = %d ", c );
}
while( ++c <= 3 ); /* This works with outer c */
/* Inner c is dead, this is outer */
printf("\n c = %d\n", c );
}
Related examples in the same category