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

What are pointer-to-members? Explain.

638


What is the latest c++ version?

615


What are the storage qualifiers?

669


What do you mean by function and operator overloading in c++?

614


How can you quickly find the number of elements stored in a static array? Why is it difficult to store linked list in an array?

587






Is empty stack c++?

525


Define stacks. Provide an example where they are useful.

584


What is an inline function in c++?

631


What do you mean by late binding?

622


Keyword mean in declaration?

600


Do the parentheses after the type name make a difference with new?

655


What is the identity function in c++? How is it useful?

555


What is the C-style character string?

609


Why #include is used?

619


How delete [] is different from delete?

604