The usage of anonymous enums

后端 未结 8 733
无人及你
无人及你 2020-11-29 19:40

What is the purpose of anonymous enum declarations such as:

enum { color = 1 };

Why not just declare int color = 1

8条回答
  •  误落风尘
    2020-11-29 20:24

    When you use
    enum {color = 1}
    you're not using any memory it's like
    #define color 1

    If you declare a variable
    int color=1 Then you're taking up memory for a value that's not to be changed.

提交回复
热议问题