What are the differences between a struct and a class in
C++?

Answer Posted / shivani

In Class Members are private by default.
In Structure Member are public by default.
structures are value typed where as classes are refernce
typed

Class can be inherited But Structure can't be inherited

In structures we cannot initilase the variable during the
declaration while in classes we can.

Structure s does not support polymorphism while class does

Structure can be declared without a tag at the first time,
but not in case of class.

e.g. struct { variables; }(struct variable list); [It would
not raise any error while comlitation]

class { access specifier: variable list; access specifier:
vari....

}; [it will cause an error while compilation]

Is This Answer Correct ?    3 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the best way to take screenshots of a window with c++ in windows?

574


What is a constructor in c++ with example?

584


Describe the role of the c++ in the tradeoff of safety vs. Usability?

717


What is a map in c++?

588


Will the following program execute?

565






If dog is a friend of boy, is boy a friend of dog?

575


Why is it called c++?

587


Explain terminate() and unexpected() function?

630


What is the difference between containment and delegation?

706


What are multiple inheritances (virtual inheritance)?

586


What is polymorphism & list its types in c++?

627


What does it mean to declare a member variable as static?

612


Can a constructor return a value?

578


What is bubble sort c++?

578


Explain data encapsulation?

612