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
Why is void main used?
Do you know what are bitwise shift operators in c programming?
What are the 4 data types?
How to write a code for reverse of string without using string functions?
What is bin sh c?
Tell me what is the purpose of 'register' keyword in c language?
Which is an example of a structural homology?
general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only
What is derived datatype in c?
a parameter passed between a calling program and a called program a) variable b) constant c) argument d) all of the above
What is main function in c?
write a c program to find the sum of five entered numbers using an array named number
What is int main () in c?
What do you mean by Recursion Function?
What is void main ()?