What is the size of an enum in C?

前端 未结 7 1851
无人及你
无人及你 2020-11-22 08:55

I\'m creating a set of enum values, but I need each enum value to be 64 bits wide. If I recall correctly, an enum is generally the same size as an int; but I thought I read

7条回答
  •  面向向阳花
    2020-11-22 09:16

    Consider this code:

    enum value{a,b,c,d,e,f,g,h,i,j,l,m,n};
    value s;
    cout << sizeof(s) << endl;
    

    It will give 4 as output. So no matter the number of elements an enum contains, its size is always fixed.

提交回复
热议问题