I created the following function named prime() that checks whether or not a number is prime and returns a boolean value accordingly.
I declared a variable count (but did not initialise it) within the function prime() to keep track of the no. of divisors of the no. being checked.
How's it that instead of a garbage value, does it store value 0 by default?
I have even added a line that prints the value of count after its declaration to confirm my observations.
Please help.
Here's the code snippet:
bool prime(int n)
{
    int count;   //non-static variable count declared, but not initialsed to 0
    printf(" value of count is %i \n", count);  //this printed 0
    bool a;
    for(int x=2; x<=n; x++)
    {
        if (n%x==0)
        count ++;
    }
    if (count == 1)
        a= true;
    else
        a= false; 
    return a;
}
 
    