Structured Data Type

User Defined Data Types

Apart from storing simple data like numbers, characters, etc. we need to store data that is of a complex format. These complex format data might contain tabular data format, graphical data format, databases, etc. To store such complex data, we require more than Built-in Data types. For this purpose, we use Complex Data types called as User defined data types. In computer science, User defined data types are data types that are used as per the user’s need.


  • In a programming language, User Defined Data Types are defined by the users in the program as per their needs in order to store data either of the same or different types as per the requirement.
  • User Defined Data types or Composite Data types are derived from more than one built-in data type which is used to store complex data.

User Defined Data Types

Data types define the type of value or data a variable holds in it. Built-in Data types are used to store simple data types such as integers, decimal point values, characters, etc. But Data also occurs in a wide variety of formats. High Complexity of data can occur often. For this purpose programming languages provides us with User-Defined Data types that are created by the users/programmers as per the data complexity requirements.

For every Programming language, there are different types of User-Defined data types. Let us look at a few of them :

  1. C/C++ Programming Language

  1. Class – A User-defined data type that holds data members and functions whose access can be specified as private, public, or protected. It uses the ‘class’ keyword for defining the data structure.
  2. Structure A structured data type is used to group data items of different types into a single type. For Eg. Structure can be Address, in which it further contains information such as Flat number, Building name, street, city, state, pin code, etc. It is defined by using the ‘struct’
  3. Union – Union is a type of data structure where all the members of that union share the same memory location. If any changes made in the Union, it will be visible to others as well. The ‘union’ keyword is used to define this type of User-defined data type.
  4. Enumeration – It helps assign names to integer constants in the program. The keyword ‘enum’ is used. It is used to increase the readability of the code.
  5. Typedef – Typedef defines a new name for an existing data type. It does not create a new data class. It makes code readability easy and gives more clarity to the user.

The syntax for defining a Typedef Data Structure is:

typedef data_type new_name ;

  1. Java/Python Programming Language

Along with structure, Union and Enumeration, Java also supports few other user-defined data types. They are:

  1. Classes
  2. Interface – Interface is a type of User-Defined data type where it specifies the behavior, the classes must implement. Once they are defined, any member of classes can implement an interface.

Browse more Topics under Structured Data Type

Benefits of User-Defined Data Types

  1. User-Defined data types store data elements of either the same types or different types. This gives more flexibility for the programmer to store different data types in a single variable as per their needs and requirements.
  2. Encapsulation – In Java/Python the variables and data values stored in User Defined Data types are hidden from other classes as per their accessibility declaration i.e. public, private, protected. The data values remain hidden and safe.
  3. Flexibility – They provide us the ability to create a data structure as per our requirements and needs.
  4. Reusability – Once defined, these data types can be reused within many definitions, saving coding time.

FAQs on User Defined Data Types

Q1. Which of the following keyword is used for defining a User-defined data type?

  1. def
  2. typedef
  3. definition
  4. int

Answer. Option B

Q2. Identify the following true statement.

  1. typedef creates a separate data type
  2. The typedef data type creates its own types
  3. typedef only creates a new name for the existing data type
  4. In programming, typedef is not a user-defined data type

Answer. Option C

Q3. ______ is a User Defined data type.

  1. Class
  2. Variable
  3. Integer
  4. None of the above

Answer. Option A

Q4. Which of the following is themselves a collection of different other data types?

  1. Union
  2. String
  3. Character
  4. Structure

Answer. Option D

Q5. User-defined data types can be derived by ______

  1. Struct
  2. Union
  3. Enumerator
  4. All of the above

Answer. Option D

Share with friends

Customize your course in 30 seconds

Which class are you in?
Get ready for all-new Live Classes!
Now learn Live with India's best teachers. Join courses with the best schedule and enjoy fun and interactive classes.
Ashhar Firdausi
IIT Roorkee
Dr. Nazma Shaik
Gaurav Tiwari
Get Started

Leave a Reply

Your email address will not be published. Required fields are marked *

Download the App

Watch lectures, practise questions and take tests on the go.

Customize your course in 30 seconds

No thanks.