- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference Between Structure and Class
In this post, we will understand the difference between structure and class.
It is defined using ‘class’ keyword.
When data is defined in a class, it is stored in memory as a reference.
It gets memory allocated only when an object of that class is created.
The reference type (before creating an object) is allocated on heap memory.
They can have constructors and destructors.
It can use inheritance to inherit properties from base class.
The ‘protected’ access modifier can be used with the data members defined inside the class.
The ‘struct’ keyword is used to define a structure.
Every member in the structure is provided with a unique memory location.
When the value of one data member is changed, it doesn’t affect other data members in structure.
It helps initialize multiple members at once.
Total size of the structure is equivalent to the sum of the size of every data member.
It is used to store various data types.
It takes memory for every member which is present within the structure.
A member can be retrieved at a time.
It supports flexible arrays.
Its instance can be created without a keyword.
It doesn’t support protected access modifier.
It doesn’t support inheritance.
It doesn’t have a constructor or destructor.
The values allocated to structures are stored in stack memory.
Kickstart Your Career
Get certified by completing the courseGet Started