Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,641 questions

55,376 answers

573 users

How to create an enumeration of constants with and without explicit values in C++

1 Answer

0 votes
/* 
   Title: Enumeration of Constants in C++ 
   Example with and without explicit values 
*/

#include <iostream>

using std::cout;
using std::endl;

// Enum WITHOUT explicit values
enum Color {
    Red,      // 0
    Green,    // 1
    Blue      // 2
};

// Enum WITH explicit and mixed values
enum Status {
    OK = 1,       // 1
    Warning = 5,  // 5
    Error,        // 6 (auto: previous + 1)
    Critical = 10 // 10
};

int main() {
    cout << "Enum without explicit values:" << endl;
    cout << "Red = " << Red << endl;
    cout << "Green = " << Green << endl;
    cout << "Blue = " << Blue << endl;

    cout << "\nEnum with explicit and mixed values:" << endl;
    cout << "OK = " << OK << endl;
    cout << "Warning = " << Warning << endl;
    cout << "Error = " << Error << endl;
    cout << "Critical = " << Critical << endl;
}


/* 
run:

Enum without explicit values:
Red = 0
Green = 1
Blue = 2

Enum with explicit and mixed values:
OK = 1
Warning = 5
Error = 6
Critical = 10

*/

 



answered Apr 25 by avibootz

Related questions

...