+ 5

⚠️ A big confusion for me! [Read Description]

Are Structure and Union user-defined datatype or derived datatype? I have googled a lot and didn't get the perfect answer to my question. Some of them say user-defined and some of them say derived, exactly what are they? Can anyone please clear my doubt! 🙏🏻

10th Feb 2021, 5:13 PM
Mahima Rajvir Singh
Mahima Rajvir Singh - avatar
5 Réponses
+ 3
It totally depends on how you are defining them (or what language you are using ) By defination User defined data types should have thier own behaviour and which is not derived/inherited from other data type. So When talking for C language where structures and unions can't have member function (and thus have to relay on functions of other data types(like int,float etc) for basic operations ), they are considered as DERIVED data types But for C++ We can add more functionality to them (via member functions ), making those capable to behave as stand alone data types and thus can be considered as USER DEFINED data types.
11th Feb 2021, 5:01 AM
Arsenic
Arsenic - avatar
+ 3
Structs and Unions are user defined. They are user defined in the sense that it is the user that will decide what goes on with them. You can decide that your struct will store an integer or character. Or it will store a union or another struct. But data types like int or float have a fixed application. Float has 4 bytes. So any number with a size greater than 4 bytes should be used with double. You have no control over that as a user. But that's not the case with structs and unions as you will decide what your struct and union entail
10th Feb 2021, 5:31 PM
Sekiro
Sekiro - avatar
+ 3
Tarvs[idle] 56 Can we even say them as derived datatype?
10th Feb 2021, 5:34 PM
Mahima Rajvir Singh
Mahima Rajvir Singh - avatar
+ 3
Technically, we can also call them derived. But that's because the framework has already been fixed. Let me put it this way. Think of it as buying a lego set. The lego pieces are already fixed. But when you build, you use the pieces to create new structures. Now, do those new structures belong to you or lego. You. That's because lego only gave you the pieces same way C gave you the name. But you built new structures with the pieces, same way you defined the structs and unions with what you were given
10th Feb 2021, 5:40 PM
Sekiro
Sekiro - avatar
+ 3
Tarvs[idle] 56 and Arsenic Thank you so much! I am now clear about it. 😄
13th Feb 2021, 7:51 AM
Mahima Rajvir Singh
Mahima Rajvir Singh - avatar