Scope modifiers: Difference between revisions

→‎{{header|bc}}: Rephrased second paragraph
(→‎{{header|C}}: Added bc)
(→‎{{header|bc}}: Rephrased second paragraph)
Line 150:
All identifiers are global by default (except function parameters which are local to the function). There is one scope modifier: <code>auto</code>. All identifiers following the <code>auto</code> statement are local to the function and it must be the first statement inside the function body if it is used. Furthermore there can only be one <code>auto</code> per function.
 
It'sOne importantcan tothink understand,of thateach allidentifier functionas a stack. Function parameters and local identifiers are pushed onto athe stack when entering the function and thus hideshadow the values of identifiers with the same namenames from the outer scopescopes. They are popped from the stockstack when the functionsfunction returns. Thus it is possible that a function whichthat is called from another function has access to the local identifiers and parameters of its caller if itself doesn't use the same name as a local identifier/parameter. In other words, always the innermost value (the value at the top of the stack) for each identifier is visible, regardless of the scope level where it is accessed.
 
<lang bc>define g(a) {