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 does catch(…) mean?

604


Explain register storage specifier.

582


Explain abstraction.

607


Why is c++ not purely object oriented?

555


Is c++ a float?

595






What is stream and its types in c++?

543


Explain how would you handle a situation where you cannot call the destructor of a local explicitly?

532


Can non graphic characters be used and processed in C++?

689


What is java and c++?

654


What is singleton class in c++?

582


What is the difference between structure and class?

538


How can you quickly find the number of elements stored in a static array?

624


What does asterisk mean in c++?

576


What is the use of 'using' declaration in c++?

615


What are the advantages of c++ over c?

572