Size of enum type

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.

CppReference.com

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,
    typeB,
    typeC
};

enum bar : typename uint64_t
{
    typeD = 0,
    typeE,
    typeF

};

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!

vote
Article Rating
Sharing is Caring
  •   
  •   
  •   
  •   
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x