In some languages like lisp
or scheme
the programmer can define variables with let
that are only available for a certain local scope. For example a function which is only called within another function.
Is there a C equivalent?
In some languages like lisp
or scheme
the programmer can define variables with let
that are only available for a certain local scope. For example a function which is only called within another function.
Is there a C equivalent?
In C, variables are local to the scope of the wrapping { } brackets they are enclosed in. This is the same in C++ and Java.
If a variable is defined outside of a function it is global to that module and can be referenced in other modules by adding an 'extern' prefix before the reference to the variable from another module in the module that wants to use it.
If a varaible is defined outside of a function and has the 'static' prefix then it is global to that module only.
When I say module this means everything contained in the same source file. Java does not support global variables, however it does support static class variables which are almost the same as globals.
Simply, if you want variable "count" has its own scope:
void test()
{
int input; //input is usable in function test()
...
{
int count; //count only usable in scope {}
...
}
}