I have a static variable declared but uninitialized in a function. Will this variable be initialized to zero automatically?
static int idx;
I have a static variable declared but uninitialized in a function. Will this variable be initialized to zero automatically?
static int idx;
Yes - the C (and C++) standards say this must be so.
As others have pointed out, it is good practice to always initialise static variables:
static int idx = 0;
The reason for doing this is not because some compiler might not always initialise static variables to zero (any compiler that failed to do such initialisation would be terminally broken, and could not claim to be a C or C++ compiler), it is to Say What You Mean - possibly the most basic rule of programming.
While the standards say yes...Good practice indicates that you should always initialise variables. You never know when you change compiler, or have to compile it on another machine, you want to minimise any potential for unexpected behaviour.