VOOZH about

URL: https://www.geeksforgeeks.org/cpp/difference-between-struct-and-enum-in-c-c-with-examples/

⇱ Difference between Struct and Enum in C/C++ with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Difference between Struct and Enum in C/C++ with Examples

Last Updated : 23 Jul, 2025

A structure is a user-defined data type in C/C++. A structure creates a data type that can be used to group items of possibly different types into a single type. The ‘struct’ keyword is used to create a structure. 

Syntax:

struct structureName{

    member1;

    member2;

    member3;

    .

    .

    .

    memberN;

};

Below is the implementation:


Output
x = 10, y = 1

Structures in C++ can contain two types of members:  

  • Data Member: These members are normal C++ variables. We can create a structure with variables of different data types in C++.
  • Member Functions: These members are normal C++ functions. Along with variables, we can also include functions inside a structure declaration.

Enum is the short name for enumeration. It is a user-defined data type. It is used to define a list of options that can be selected. Once, enum is declared we cannot change its value, the compiler will throw an error. Two enumerations cannot share the same names.

enum enumName{

    member1;

    member2;

    member3;

    .

    .

    .

    memberN;

};

Below is the implementation:


Output
0
1
2
3
4
5
6
7
8
9
10
11


S No.StructEnum
1The "struct" keyword is used to declare a structureThe "enum" keyword is used to declare enum.
2The structure is a user-defined data type that is a collection of dissimilar data types.Enum is to define a collection of options available.
3A struct can contain both data variables and methods. Enum can only contain data types.
4A struct supports a private but not protected access specifier.Enum does not have private and protected access specifier.
5Structure supports encapsulation.Enum doesn't support encapsulation.
6When the structure is declared, the values of its objects can be modified.Once the enum is declared, its value cannot be changed, otherwise, the compiler will throw an error.
7

Struct only contains parameterized constructors and no destructors. 

The compiler does not generate a default constructor for a struct.

Enum does not contain constructors and destructors.
8The values allocated to the structure are stored in stack memory.The memory to enum data types is allocated in the stack.
Comment
Article Tags: