C
When a variable is not initialized in main function it contains garbage value. This can be well seen from the example below
main()
{
int x;
printf(“%d”,x);
z= sample()
}
sample()
{
printf(“Testing program”);
}
Output is
x=80
Testing program
The above program prints a garbage value and the output testing program. This is because the variable x is not initialized and so the variable x had garbage value which is printed first then the function sample is called which gave output as testing program. Thus it is essential to initialize variables in main () function.

| I think when a variable is declared outside main() then it becomes global variable so it can be used anywhere in the program. |

| it simply takes a garbage value in case if declared within the main() |
| It shows error that the variable is not initialised |

|
when a variable is not declared in the main function ,you can't use the varaible in the program unless it is a global variable. initialisation is required to give some value to the declared variable.(it depends upon the logic you are using to solve the problem.) if you dont initialise , first it will store a garbage value it. if is is not overwritten in the course of the program, then when you print the variable a garbage value will be printed................. |