What is the difference between Class and Structure?

Answer Posted / sanjay yadav

# 5
Structs are Value type. They are stored as a stack on
memory.
Class is reference type. They are stored as heap on memory.
Sturcts constructor must contain a parameter and cannot
have default constructor.
Class constructor may contain no parameter.
Struct cannot have instance field.
Class can have instance field.
Struct cannot inherit from a structure.
Class can inherit from a class.
Structs cannot declare a destructor.

structure :- In structure have a by default public.
In class have a by default private.
Structure cannot be inherited. But class can be
inherit.
There is no data hiding features comes with
structures. Classes do, private, protected and public.
A structure can't be abstract, a class can.
A structure is a value type, while a class is a
reference type.
A structure is contain only data member , but class
contain data member and member function.
In a Structure we can't initilse the value to the
variable but in class variable we assign the values.
Structure are value type, They are stored as a
stack on memory. where as class are reference type. They
are stored as heap on memory.

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why c++ is so important?

613


What is the difference between cin.read() and cin.getline()?

563


List the issue that the auto_ptr object handles?

621


Define pure virtual function?

568


What is a terminating character in c++?

777






List the types of polymorphism in c++?

631


Is main a class in c++?

568


Explain bubble sorting.

633


What is c++ and its features?

580


Reverse the Linked List. Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL

344


How would you call C functions from C++ and vice versa?

642


Who made c++?

618


Write about all the implicit member functions of a class?

604


What is the difference between containment and delegation?

710


How does list r; differs from list r();?

699