Difference between Class and Struct.

Answer Posted / naresh kukreti

The struct default access type is public. A struct should
typically be used for grouping data.

The class default access type is private, and the default
mode for inheritance is private. A class should be used for
grouping data and methods that operate on that data.

In short, the convention is to use struct when the purpose
is to group data, and use classes when we require data
abstraction and, perhaps inheritance.

In C++ structures and classes are passed by value, unless
explicitly de-referenced. In other languages classes and
structures may have distinct semantics - ie. objects
(instances of classes) may be passed by reference and
structures may be passed by value.

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is malloc memset faster than calloc?

787


How can I sort more data than will fit in memory?

866


Are pointers integer?

745


Which header file should you include if you are to develop a function which can accept variable number of arguments?

1033


What is the benefit of using const for declaring constants?

786


What are the header files used in c language?

770


What is dynamic memory allocation?

1027


What is pass by value in c?

765


explain how do you use macro?

886


What is use of null pointer in c?

730


What are the parts of c program?

834


List the variables are used for writing doubly linked list program.

1803


Is fortran still used today?

789


What are the types of pointers?

773


Between macros and functions,which is better to use and why?

1791