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
How can I get the current date or time of day in a c program?
What is I ++ in c programming?
What are control structures? What are the different types?
What the advantages of using Unions?
When would you use a pointer to a function?
Which control loop is recommended if you have to execute set of statements for fixed number of times?
what are bit fields? What is the use of bit fields in a structure declaration?
What is the usage of the pointer in c?
What is main () in c language?
If jack lies on Mon, Tue Wed and jill lies on Thursday, Friday and Saturday. If both together tell they lied yesterday. So c the given options and then c cos in the given dates one will be saying the truth and one will be lying. I got Thursday as option because jack is saying the truth he lied yest but jill is lying again as he lies on that day.
writ a program to compare using strcmp VIVA and viva with its output.
What is a good way to implement complex numbers in c?
What is dynamic variable in c?
What is page thrashing?
How do you define CONSTANT in C?