What’s the difference between classes in cpp and structs in c language? | SoloLearn: Learn to code for FREE!

+11

What’s the difference between classes in cpp and structs in c language?

3/25/2020 7:19:33 PM

Nika Soltani Tehrani

10 Answers

New Answer

+21

Nika Soltani Tehrani A structure is used for handling a group of logically related data(only data) items. They do not permit data hiding and their members are public by default. Standard C doesn't allow struct data type to be treated like built-in type. Class is used to hold data and function both and by default members of class are private. This work as built-in DT.

+15

Nika Soltani Tehrani 😃🙏

+13

structure contain data members only which is by default public. For example: struct structure_name{ Data member 1; Data member 2; Data member3; }; Classes contain data members and member functions also. Which is by default private. Classes contain protected member also. For example:- class class_name{ data member; member function; };

+5

Such valuable information Vinesh Wadhwani🇮🇳 Thanks a lot🙏😊

+5

Thank you so much Saad Mughal for your help🙏

+4

Both have different too visit this site you can understood in better way https://www.google.com/amp/s/www.geeksforgeeks.org/difference-between-class-and-structure-in-c-sharp/amp/

+2

In struct all of your data is public by default In classes all of your data is private by default

+2

A few days ago I discussed with a friend if it was possible to do object-oriented programming only with structure and function pointers, I think the basics of the concept can be done, but the facilities that the classes have in terms of handling and permissions are a big difference.

+2

 Structs are value type whereas Classes are reference type. Structs are stored on the stack whereas Classes are stored on the heap. ... Structs can not have explicit parameterless constructors whereas a class can structs doesn't support inheritance, but classes do.

0

Nika Soltani Tehrani welcome