Classes | Structures |
It is used for large amounts of data. | It is used for smaller amounts of data. |
It can be inherited. | It cannot be inherited. |
It can be NULL. | It cannot be NULL like the class. |
It can have destructor. | It cannot have destructor. |
It can be abstract. | It cannot be abstract. |
The keyword for class is 'class'. | The keyword for structure is 'struct'. |
Class member variables are private by default. | Structure members have public access by default. |
It contains a volatile field. | It cannot contain volatile field. |
Fields are automatically initialized. | Fields are not automatically initialized. |
You cannot use sizeof operator. | You can use sizeof operator. |
Syntax: class <Class_name> { static void main(string[ ] args) { //Statements } } | Syntax: struct <Structure_name> { //variable_declaration }; |
Example: class A { static void main(string[ ] args) { //Statements } } | Example: struct Student { int rollno; char stud_name; char address; }; |