Structures | class |
---|---|
A structure is a user-defined data type which contains variables of dissimilar data types. | The class is a user-defined data type which contains member variables and member functions. |
The variables of a structure are stored in the stack memory. | The variables of a class are stored in the heap memory. |
We cannot initialize the variables directly. | We can initialize the member variables directly. |
If access specifier is not specified, then by default the access specifier of the variable is “public”. | If access specifier is not specified, then by default the access specifier of a variable is “private”. |
The instance of a structure is a “structure variable”. | |
Declaration of a structure:struct structure_name { // body of structure; } ; | Declaration of class:class class_name { // body of class; } |
A structure is declared by using a struct keyword. | The class is declared by using a class keyword. |
The structure does not support the inheritance. | The class supports the concept of inheritance. |
The type of a structure is a value type. | The type of a class is a reference type. |