1
0

hiding.c 549 B

12345678910111213141516171819202122
  1. // hiding.c -- variables in blocks
  2. #include <stdio.h>
  3. int main()
  4. {
  5. int x = 30; // original x
  6. printf("x in outer block: %d at %p\n", x, &x);
  7. {
  8. int x = 77; // new x, hides first x
  9. printf("x in inner block: %d at %p\n", x, &x);
  10. }
  11. printf("x in outer block: %d at %p\n", x, &x);
  12. while (x++ < 33) // original x
  13. {
  14. int x = 100; // new x, hides first x
  15. x++;
  16. printf("x in while loop: %d at %p\n", x, &x);
  17. }
  18. printf("x in outer block: %d at %p\n", x, &x);
  19. return 0;
  20. }