Difference between Struct and Enum in C/C++ with Examples Last Updated : 05 Sep, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Structure in C++ 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: C++ #include<stdio.h> struct Point { int x, y; }; int main() { struct Point p1 = {0, 1}; // Accessing members of point p1 p1.x = 10; printf ("x = %d, y = %d", p1.x, p1.y); return 0; } Outputx = 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 in C++ 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: C++ #include <bits/stdc++.h> using namespace std; // Defining enum Year enum year { Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec }; // Driver Code int main() { int i; // Traversing the enum year for (i = Jan; i <= Dec; i++) cout << i << endl; return 0; } Output0 1 2 3 4 5 6 7 8 9 10 11Difference between Struct and Enum S No.StructEnum1The "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 More infoAdvertise with us Next Article C++ - Difference Between Functors and Functions R rn540 Follow Improve Article Tags : C++ C-Struct-Union-Enum Practice Tags : CPP Similar Reads Difference Between Structure and Class in C++ In C++, a structure works the same way as a class, except for just two small differences. The most important of them is hiding implementation details. A structure will by default not hide its implementation details from whoever uses it in code, while a class by default hides all its implementation d 3 min read Difference Between C Structures and C++ Structures Let's discuss, what are the differences between structures in C and structures in C++? In C++, structures are similar to classes. Differences Between the C and C++ StructuresC Structures C++ Structures Only data members are allowed, it cannot have member functions.Can hold both: member functions and 6 min read Difference Between STL and Standard Library in C++ In C++, the term "Standard Library" and "Standard Template Library" are often misinterpreted as the same. Although they sound same with only a single word difference, they refer to the different part of the C++ programming language. In this article, we will learn what's the difference between the C+ 3 min read C++ - Difference Between Functors and Functions In C++, we have multiple options to operate over the data like in the case where we can use functions and functors. Although both seem to be similar in a few ways but have multiple differences between them. Let's check the differences between functions and functors in C++. What are functions? Functi 3 min read Difference between Abstraction and Encapsulation in C++ Abstraction:Â In OOPs, Abstraction is the method of getting information where the information needed will be taken in such a simplest way that solely the required components are extracted, and also the ones that are considered less significant are unnoticed. The concept of abstraction only shows nece 3 min read Storage Classes in C++ with Examples C++ Storage Classes are used to describe the characteristics of a variable/function. It determines the lifetime, visibility, default value, and storage location which helps us to trace the existence of a particular variable during the runtime of a program. Storage class specifiers are used to specif 6 min read Like