Comparison
between Structure and Class:
between Structure and Class:
▪
Structure and class are user defied data types
Structure and class are user defied data types
▪
By default, structure is a public whereas class is private
By default, structure is a public whereas class is private
▪
Class implements the principal of encapsulation
Class implements the principal of encapsulation
▪
Objects of a class are created on the heap memory
Objects of a class are created on the heap memory
▪
Class is used for re usability whereas structure is used for
grouping the data in the same structure
Class is used for re usability whereas structure is used for
grouping the data in the same structure
▪
Structure data members cannot be initialized directly but they
can be assigned by the outside the structure
Structure data members cannot be initialized directly but they
can be assigned by the outside the structure
▪
Class data members can be initialized directly by the parameter
less constructor and assigned by the parameterized constructor.
Class data members can be initialized directly by the parameter
less constructor and assigned by the parameterized constructor.