-1
  #include<stdio.h>
  int i=5;
  main()
  {
 int i=6;
  {

    int i=7;
    printf("%d",i);

  }
   printf("%d",i);
  }

Why does the above code doesnot give a variable redifinition error..Although the variable i is defined outside of block also??

2
Contributors
1
Reply
13
Views
5 Years
Discussion Span
Last Post by Moschops
1

You are allowed to redefine a variable inside a deeper scope. This is commonly called "shadowing" and it's generally regarded as a bad idea.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.