0% found this document useful (0 votes)
96 views

User Defined Data Types

Structures allow for the grouping of different data types together under one name. Each member of a structure has its own storage location. Unions also group various data types but all members share the same memory location. Enumerations define a data type consisting of a set of named values (or enumerators) and can be used to assign human-readable names to constants. Classes are user-defined data types that group together data members (variables) and member functions (methods) that operate on those data members.

Uploaded by

avrharinath
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views

User Defined Data Types

Structures allow for the grouping of different data types together under one name. Each member of a structure has its own storage location. Unions also group various data types but all members share the same memory location. Enumerations define a data type consisting of a set of named values (or enumerators) and can be used to assign human-readable names to constants. Classes are user-defined data types that group together data members (variables) and member functions (methods) that operate on those data members.

Uploaded by

avrharinath
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

USER-DEFINED DATATYPES STRUCTURES Structure is a user-defined data type and it is a collection of data items of different 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(); }

You might also like