+ 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! 🙏🏻
5 Respostas
+ 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.
+ 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
+ 3
Tarvs[idle] 56 Can we even say them as derived datatype?
+ 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
+ 3
Tarvs[idle] 56 and Arsenic
Thank you so much! I am now clear about it. 😄