What is the difference between classes and structures?

The class and structure are almost similar but there are some differences which are discussed below

Image result for what is the difference between classes and structures

  1. Class offers the flexibility for linking data and it gives the e re-usability called inheritance whereas the structure can be used for grouping data.
  2. Class is used as a reference type whereas the structure is used as a value type. The object of the class is made on the heap memory while the object of the structure is made on the stack memory. It means class is pass by reference type and the structure is pass-by-copy.
  3. Class also makes a subclass which will receive the properties and methods of parents that mean class supported inheritance but the structure is not supported the inheritance.
  4. Classes can be used as a garbage collector which works on heap memory whereas structure cannot be used a garbage collector thus there is no efficient memory management.
  5. Structures are good for small and isolated model objects whereas the classes are suitable for larger or complex objects.
  6. All members of a structure are public whereas all the members of a class are private.
  7. The empty structure is of zero byte whereas the empty class is of one byte.
  8. The object of a structure cannot be created with the use of new keyboard whereas the object of a class can be created with the use of new keyword.

4 Comments Add yours

  1. jyo says:

    Explained Beauuuuutifully 💯

    Liked by 2 people

    1. daneelyunus says:

      Thank you so much

      Liked by 1 person

  2. lescrive says:


    Liked by 2 people

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s