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


Please Help Members By Posting Answers For Below Questions

WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.

2253


What does char * * argv mean in c?

817


What are header files why are they important?

831


Write a program to print all permutations of a given string.

943


What are pragmas and what are they good for?

758


Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?

801


What does malloc () calloc () realloc () free () do?

792


How do you determine whether to use a stream function or a low-level function?

914


explain what is an endless loop?

829


What is meant by errors and debugging?

868


What is a file descriptor in c?

816


Explain what does a function declared as pascal do differently?

920


What is wrong with this statement? Myname = 'robin';

1058


What is the value of uninitialized variable in c?

797


What’s a signal? Explain what do I use signals for?

854