Does the local area belong to the scope?
Yes. In most languages ββof C-variables, variables are valid in the area in which they are declared. If you declare a variable inside a function, but not inside any other block of code, then this variable is usually called a "local" or "automatic" variable. You can access it anywhere in the function. On the other hand, if you declare your variable inside another block of code - say, in the body of a conditional statement, then the variable is valid only inside this block. A few other answers here give good examples.
and what does it mean that only labels have a function scope?
A context would be useful, but that means you cannot go from one function to a label in another function.
void foo(int a) { if (a == 0) goto here; // okay -- 'here' is inside this function printf("a is not zero\n"); goto there; // not okay -- 'there' is not inside this function here: return; } void bar(int b) { if (b == 0) goto there; // okay -- 'there' is in this function printf("b is not zero\n"); there: return; }
Do not arouse the hornet's nest, but the volume of the labels probably will not appear too often. Shortcuts are mostly useful with the goto
, which is very rarely needed, if ever, and even if you decided to use goto
, you probably wouldn't even think about trying to switch to another function.
Caleb source share