Q:

Why the variable 'i' is returning a value of 0 when even not initialized?

void main()
{
    int i, n, count = 0;
    printf("%d\n", i);
    printf("%d\n", n);

    while (count != 10)
    {
        printf("%d", i);
        i++;
        count++;
    }
}

IF it is giving me some garbage value then how can be the same value be assigned to 'n' variable?

A:

As you already observed, the value of i is indeterminate. It happens to be zero in your environment. With a different compiler, it might happen to be something else. There's no mystery there, just happenstance.

If it is giving me some garbage value then how can be the same value
be assigned to 'n' variable?

It can't, reliably. (It will work on some compilers, and on most with optimization disabled, but in general, you can't reliably duplicate an uninitialized variable's indeterminate value.)

