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
Difference between a copy constructor and an assignment operator.
What are the uses of pointers?
What is helper in c++?
How does code-bloating occur in c++?
How do you find out if a linked-list has an end? (I.e. The list is not a cycle)
What is implicit pointer in c++?
Can non-public members of another instance of the class be retrieved by the method of the same class?
What is the use of object in c++?
What is array give example?
What is encapsulation in c++?
How do I write a c++ program?
What is the difference between the indirection operator and the address of oper-ator?
Is swift faster than c++?
What are exceptions c++?
Can you please explain the difference between using macro and inline functions?