int main ()

{
	int x = 5;
	
	printf ( "\n\n\tThe Local x out of the scope of main is: %d", x );

	{ /* Starts a new scope */
		int x = 7; /* Local variable with new scope */
		printf ( "\n\tThe Local x in the internal scope of main is: %d", x );	
	} /* End of the new scope */

	printf ( "\n\tThe Local x  in the external scope of main is: %d", x );

	useLocal (); /* Contains a Local x */
	useStaticLocal (); /* Contains a local static x */
	useGlobal (); /* Use a Global x */
	useLocal (); /* Re-Initializes a local automatic x */
        useStaticLocal (); /* Retains the previous value of x */
     	useGlobal (); /* x Global also retains his previous value */ 

	printf ( "\n\n\tThe x Local in main is: %d", x );
	printf ( "\n\n\n" );
	return 0;
} /* End of the main */
Exemple #2
0
/* function main begins program execution */
int main( void )
{
    int x = 5; /* local variable to main */

    printf("local x in outer scope of main is %d\n", x );

    {   /* start new scope */
        int x = 7; /* local variable to new scope */

        printf( "local x in inner scope of main is %d\n", x );
    } /* end new scope */

    printf( "local x in outer scope of main is %d\n", x );

    useLocal();     /* useLocal has automatic local x */
    useStaticLocal(); /* useStaticLocal has static local x */
    useGlobal();      /* useGlobal uses global x */
    useLocal();       /* useLocal reinitializes automatic local x */
    useStaticLocal(); /* static local x retains its prior value */
    useGlobal();      /* global x also retains its value */

    printf( "\nlocal x in main is %d\n", x );

    return 0; /* indicates successful termination */

} /* end main */
void scopeExersice(void){
    
    int x = 5;
    
    printf("Local x in outer scope of main is %d\n", x);
    
    {
        int x =7;
        printf("Local x in outer scope of main is %d\n", x);
    }
    
    printf("Local x in outer scope of main is %d\n", x);
    
    useLocal();
    useStaticLocal();
    useGlobal();
    useLocal();
    useStaticLocal();
    useGlobal();
    
    printf("\nLocal x in outer scope of main is %d\n", x);
}
Exemple #4
0
int main(void){
  int x = 5;

  printf("Local x in outer scope of main is %d\n", x);

  {
    int x = 7;
    printf("Local x in inner scope of main is %d\n", x);
  }

  printf("local x in outer scope of main is %d\n", x);

  useLocal();
  useStaticLocal();
  useGlobal();
  useLocal();
  useStaticLocal();
  useGlobal();

  printf("\nlocal x in main is %d\n", x);

  return 0;
}