What is the difference between Class and Structure?
Answer Posted / sanjay yadav
# 5
Structs are Value type. They are stored as a stack on
memory.
Class is reference type. They are stored as heap on memory.
Sturcts constructor must contain a parameter and cannot
have default constructor.
Class constructor may contain no parameter.
Struct cannot have instance field.
Class can have instance field.
Struct cannot inherit from a structure.
Class can inherit from a class.
Structs cannot declare a destructor.
structure :- In structure have a by default public.
In class have a by default private.
Structure cannot be inherited. But class can be
inherit.
There is no data hiding features comes with
structures. Classes do, private, protected and public.
A structure can't be abstract, a class can.
A structure is a value type, while a class is a
reference type.
A structure is contain only data member , but class
contain data member and member function.
In a Structure we can't initilse the value to the
variable but in class variable we assign the values.
Structure are value type, They are stored as a
stack on memory. where as class are reference type. They
are stored as heap on memory.
| Is This Answer Correct ? | 1 Yes | 2 No |
Post New Answer View All Answers
What is c++ mutable?
What is stl containers in c++?
How important is c++?
What is vector pair in c++?
. If employee B is the boss of A and C is the boss of B and D is the boss of C and E is the boss of D. Then write a program using the Database such that if an employee name is Asked to Display it also display his bosses with his name. For eg. If C is displayed it should also display D and E with C?
How we can differentiate between a pre and post increment operators during overloading?
Why do we need runtime polymorphism in c++?
What do you mean by a template?
What's c++ used for?
what is COPY CONSTRUCTOR and what is it used for?
What is a sequence in c++?
Explain the difference between static and dynamic binding of functions?
Const char *p , char const *p What is the difference between the above two?
What is a singleton class c++?
What is tellg () in c++?