Each set of braces denotes a separate scope, so if you create a block with braces, and declare variables inside them, they will not be viisble outside of it. If you create nested blocks of braces, they have inner block has access to the outer block, but not the other way around.
This also applies not only to function (which always have their scope), but also to blocks inside a function as well.
i.e. Two different variables named i
, no nameclash because of different scopes:
{
int i;
}
{
int i;
}
Here we have access.
{
int i;
{
int x = i; <== in scope
}
int y = x; <== error
}
If you want to have a set ov variables assoicated to some logical function, then you should put them inside a class or struct.