We have already discovered that the a variable is not given a sensible value when you declare it. Instead you must remember to give it a sensible value before you use it. We can combine the declaration and initialization into a single action if we wish:
/* counter for the sheep */
int sheep = 0 ;
This would create an integer variable called sheep which is then set to the value 0. If we want we can perform multiple declaration and initialization (and without a safety net too!)
/* .. as used by Old MacDonald.. */
int sheep = 0,
goats = 0,
cows = 0,
pigs = 0 ;
I have spread the declaration over a number of lines. The compiler doesn't mind this, and I think it makes the code look clearer.
/* Simple Variable */
void main ( void )
{
/* create an integer variable */
int count ;
set the value to 99 */
count = 99 ;
/* increase count by 1 */
count = count + 1 ;
}