Difference between Class and Struct.
Answer Posted / kishore
What is the difference between class and structure?
1) Structure: Initially (in C) a structure was used to
bundle different type of data types together to perform a
particular functionality. But C++ extended the structure to
contain functions also. The major difference is that all
declarations inside a structure are by default public.
Class: Class is a successor of Structure. By default all
the members inside the class are private.
2) structures in c++ doesn't provide data hiding where as a
class provides data hiding
classes support polymorphism, whereas structures don't
3) class and structure are very similar. the former is
heavyweight while the latter is light weight. reference to
the former rests on the heap..while the latter in whole
(instance and data) rests on the stack. therefor care
should be taken not to make a struct very heavy else it
overloads the stack causing memory hogging. class needs to
have an instance explicitly created to be used. A struct
doesn't have to be explicitly initiated
Is This Answer Correct ? | 44 Yes | 7 No |
Post New Answer View All Answers
WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.
What does char * * argv mean in c?
What are header files why are they important?
Write a program to print all permutations of a given string.
What are pragmas and what are they good for?
Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?
What does malloc () calloc () realloc () free () do?
How do you determine whether to use a stream function or a low-level function?
explain what is an endless loop?
What is meant by errors and debugging?
What is a file descriptor in c?
Explain what does a function declared as pascal do differently?
What is wrong with this statement? Myname = 'robin';
What is the value of uninitialized variable in c?
What’s a signal? Explain what do I use signals for?