User Defined Data Types
User Defined Data Types
In Structure each member has its own storage location. Syntax: struct struct_name { data_type element_1; . data_type element_x; }; void main () { struct struct_name v1, v2, vn ; //where v1, v2, vn are struct variable } UNION Union is a user-defined data type and it is declared like structure. The difference between Union and Structure is in terms of storage. In Structure each member has its own storage location, whereas all the members of Union use the same memory location. ENUMERATION DATA-TYPES: Enumeration type is a user defined simple data type. The following items are needed to define an enumeration type: A name for the data type A set of values for the data type A set of operations on the values Syntax: enum typeName {value1, value2 }; Example: enum sports {basketball, football, hockey, baseball, soccer, volleyball}; The default value assigned to these enumerators starts at 0 and continues as 1, 2, 3 (Different values other than the default valuescan be assigned.) CLASSES Class is a user defined data types. The variables declared inside the class are known as data members and the functions are known as member functions. The variables of Class are Objects. Syntax: class class_name { private: data_members; -----------public: member functions(); }