Can someone please explain the concept of Enumeration !
Thanks
Can someone please explain the concept of Enumeration !
Thanks
enumaration is a way to assign integers to keywords, to make code clearer to read.
for example:
enum Dir{Left,Right};
cout << DirectionValue << endl;
cout << DirectionValue[Right] << endl;
(Code block behaves weird with not decoding < to <)
This results in outputting DirectionValue[0] and DirectionValue[1] respectively but is easier to read. It is more intended for production code, and I have not seen it used in a competitive scenario.
Note 1: Dir is itβs own datatype, which means it will need casting in some cases.
Note 2: You can start numbering at somewhere else than 0:
enum Dir{Left=-1,Straight,Right}