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
Explain 'this' pointer and what would happen if a pointer is deleted twice?
Which coding certification is best?
What is the difference between passing by reference and passing a reference?
Is it possible to use a new for the reallocation of pointers ?
Explain what are accessor methods?
If a base class declares a function to be virtual, and a derived class does not use the term virtual when overriding that class, is it still virtual when inherited by a third-generation class?
What is basic if statement syntax?
Can we delete this pointer in c++?
Is c++ the hardest language?
How much do coding jobs pay?
When can I use a forward declaration?
Can circle be called an ellipse?
Differentiate between a template class and class template in c++?
What is class and structure in c++?
How java is different from c and c++?