Skip to content

Instantly share code, notes, and snippets.

@Ayoush
Created January 15, 2016 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ayoush/b04b2a12bd4de6a2c01c to your computer and use it in GitHub Desktop.
Save Ayoush/b04b2a12bd4de6a2c01c to your computer and use it in GitHub Desktop.
int main()
{
{
int x = 10, y = 20;
{
// The outer block contains declaration of x and y, so
// following statement is valid and prints 10 and 20
printf("x = %d, y = %d\n", x, y);
{
// y is declared again, so outer block y is not accessible
// in this block
int y = 40;
x++; // Changes the outer block variable x to 11
y++; // Changes this block's variable y to 41
printf("x = %d, y = %d\n", x, y);
}
// This statement accesses only outer block's variables
printf("x = %d, y = %d\n", x, y);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment