+ 12
What’s the difference between classes in cpp and structs in c language?
10 Respuestas
+ 24
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.
+ 16
+ 6
Such valuable information Vinesh Wadhwani🇮🇳
Thanks a lot🙏😊
+ 6
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/
+ 3
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.
+ 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.
+ 1
In class, we have access specifiers to protect data from unknown persons and we can also add behavior to the objects using functions. struct data members will consume memory for each data type and it'll add the memory space of each data member. By default, the data members are public in structures. while in class, by default the data members are private which will protect the data from unknown persons and we can also use destructors to deallocate the data members to store the memory.
0
Nika Soltani Tehrani welcome