A local variable exists within a particular block. It is declared right at the very start of the block, immediately after the opening curly bracket (or brace). You can declare as many local variables as you like. The thing about local variables is that they cease to exist when your program leaves the block in which they are declared.
In the program on the right you can see two variables, one called count and the other called value. When you run the program there are no variables present until you reach the first declaration. At this point the variable count comes into being. We then do a test on the value in count which is guaranteed to succeed, at which point we enter another block. Inside the block we have declared a variable called value. This appears as soon as we declare it and we can use it just like any other variable.
However, when we leave the block the variable vanishes, along with the number it used to hold.
You may think that this is rather stupid, in that we have variables which will self-destruct. However, these can be very useful. If you need a variable just for a little calculation you can create it, use it and discard it without affecting any other variables in the program. What is more, you are not wasting computer memory using variables which are not needed for the entire program.
/* Local Variable */
void main ( void )
{
/* create an integer variable */
int count = 21 ;
if ( count == 21 )
{
/* start a new block */
/* make local variable */
int value ;
value = count + ;
}
/* value has disappeared */
}