Can anyone explain diagrammatically how enum is stored in memory?

前端 未结 3 874
一生所求
一生所求 2021-01-23 03:47

How Enumeration datatype is stored in memory?Is enum really stored in memory in stack?How each value of enum is accessed?

i have gone through many blogs stating that

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-23 04:09

    enums are not allocated in memory - they exist only on compilation stage. They only exist to tell compiler what value is Tuesday in ur example. When code runs - there is no enums there anymore.

    It does same thing as below

    #define Monday 0;
    #define Tuesday 1;
    .
    .
    .
    .
    #define Sunday 6;
    

    But we prefer enums than define because easier to support and read the code with enums then with #defines.

    u can get clarity of enum size by this Stackoverflow answer

提交回复
热议问题