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 kind of jobs can I get with c++?

594


Explain this pointer?

580


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

611


Which is not a valid keyword a) public b) protected c) guarded

740


What is the rule of three?

566






How do I run c++?

572


Explain some examples of operator overloading?

645


What is searching? Explain linear and binary search.

583


What is the default access level?

621


What is cout flush?

568


What is type of 'this' pointer?

596


Why is c++ called oops?

552


What is a node class in c++?

642


Is c++ a low level language?

511


What is a string example?

547