by Dinesh Thakur Category: Type And Variables

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.



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.