devxlogo

Uninitialized enum Variables

Uninitialized enum Variables

The value of an uninitialized automatic enum variable is indeterminate. Uninitialized global and static enum variables have a zero value by default. In this regard, enum variables are similar to fundamental types such as int and char. However, unlike int and char, an uninitialized enum might have a value that is beyond the range of its enumerators. In the following example, the global enum variable st is initialized to zero. Yet none of Stat’s enumerators equals zero. Therefore, using st before assigning a valid value to it results unpredictable behavior:

 enum Stat {good=1, bad=2}; // no enumerator equals zeroStat st; // bad, initialized to 0 by defaultint main(){ if(st==good) //always false //
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist