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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,990 questions

51,935 answers

573 users

How to use enum as array index in C++

1 Answer

0 votes
#include <iostream>

enum Example {
   A, // 0
   B, // 1
   C, // 2
   D, // 3
   E, // 4
   MAX // 5
};

int main () {
   int i = 0;
   int arr[MAX] = {31, 88, 99, 10, 79};
   
   std::cout << arr[A];
}



/*
run:

31

*/

 



answered Mar 13, 2022 by avibootz

Related questions

1 answer 135 views
135 views asked Mar 13, 2022 by avibootz
1 answer 156 views
156 views asked Aug 23, 2017 by avibootz
1 answer 152 views
1 answer 123 views
1 answer 133 views
1 answer 132 views
132 views asked May 22, 2018 by avibootz
1 answer 219 views
...