BLOCK STRUCTURE:-
Ø
In
‘c’, variables can be defined in a block-structured fashion within a
function. Declaration of variables may
follow the left brace that starts any compound statement.
Ø
Variables
declared inside a block are not affected by identically named variables in
outer blocks.
Ø
An
automatic variable is initialized every time when the block is entered whereas
a static variable initialized only once at the time it enters the block.
Ex:- int a=20;
main()
{
int a=10;
{
int a=30;
printf("a=%d", a);
}
printf("a=%d",a);
show();
getch();
}
show()
{
printf("a=%d",a);
{
int
a=50;
printf("a=%d",a);
}
}
Out
put of above program is a=30 , a=10,
a=20, a=50.
No comments:
Post a Comment