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

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,037 questions

40,897 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 79 views
79 views asked Mar 13, 2022 by avibootz
1 answer 83 views
83 views asked Aug 23, 2017 by avibootz
1 answer 70 views
70 views asked May 22, 2018 by avibootz
1 answer 35 views
1 answer 56 views
...