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
What do you mean by scope of a variable in c?
How to explain the final year project as a fresher please answer with sample project
What is difference between %d and %i in c?
What are shell structures used for?
What is the role of this pointer?
Why double pointer is used in c?
Why malloc is faster than calloc?
What is volatile variable how do you declare it?
why use "return" statement a) on executing the return statement it immediately transfers the control back to the calling program b) it returns the value present in the parentheses return, to the calling program c) a & b d) none of the above
What is static and auto variables in c?
why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???
What could possibly be the problem if a valid function name such as tolower() is being reported by the C compiler as undefined?
What is difference between structure and union in c programming?
What is integer constants?
Can we assign integer value to char in c?