main()
{
int s=1,r=2;
{
int s;
s=r+4;
}
printf("%d",s);
}
output
1
How?
Though i declare 's' variable for 2 times,there's no error. How?
Block scope( '{ }' ):
if you declare a variable a block ,it's valid for that particular block only.
so
{
int s; //valid for this block
s=r+4;
}
when it come outside of the block, above declared 's' only valid. so s=6 is inside the block and s=1 is outside of the block.
To understand clearly consider this program.,
#include < stdio.h >
main()
{
int a=2;
{
int a=3;
printf("%d",a);
}
printf("%d",a);
}
OUTPUT
3 2