Size of enum type

  • Post category:C++
  • Reading time:1 mins read
  • Post comments:0 Comments

Definition of the “enum” type:

An enumeration is a distinct type whose value is restricted to a range of values (see below for details), which may include several explicitly named constants (“enumerators“). The values of the constants are values of an integral type known as the underlying type of the enumeration.

Size of the enum type

If you have read carefully the definition of the enum type, then it should be easy for you to provide the correct answer to the following problem:

#include <iostream>

enum foo
    typeA = 0,

enum bar : typename uint64_t
    typeD = 0,


int main()
    std::cout << "Size of <foo> type variable: " << sizeof(foo) << " bytes" << std::endl;
    std::cout << "Size of <bar> type variable: " << sizeof(bar) << " bytes" << std::endl;

    return 0;

Which is the calculated size of the enum type?

Please, find the correct answer below:

Unlock now all the premium content in this page.

Sign-in or register to buy access to this content using your virtual coins.

0 persons like you have already done it. Do not miss it!


Pietro L. C

C++ Software Engineer, Ph.D. working in Malta on embedded systems with a vision in mind: design best software to solve complex problems in the real world.
0 0 votes
Rated by members
Notify of