Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the values of enum members be automatically decremented instead of incremented?

Tags:

c++

enums

For example:

enum ABC
{
  apple =  0xe,
  banana = 0xd,
  orange,
  pineapple
}

Can orange automatically get the value of 0xc and pineapple 0xb?

like image 701
Anders Lind Avatar asked Nov 22 '25 16:11

Anders Lind


1 Answers

No, the values can only automatically increment. If you want the values to go the other way then you can reverse the order of the names.

enum ABC
{
   pineapple = 0xb,
   orange,
   banana,
   apple
};
like image 155
bames53 Avatar answered Nov 25 '25 06:11

bames53



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!