Data types vs data structure
What is a data type?
The two things we must know about the data types are:
If the data is of int (integer) type
Then it takes only integer values
Operations that can be performed on the data type are addition, subtraction, multiplication, bitwise operations, etc.
If the data is of float (floating) type
Then it takes only floating type values.
Operations that can be performed on the data type are addition, subtraction, multiplication, division, etc. (bitwise and % operations are not allowed).
So, it is cleared from the above examples that data type does not only define a certain domain of values but also defines operations that can be performed on those values.
User-defined data type
In contrast to primitive data types, there is a concept of user-defined data types. The values and the operations that can be performed on the primitive data types are not specified by the language itself, but it is specified by the user only. The examples of user-defined data types are structure, union, and enumeration. By using the structures, we can define our own type by combining other primitive data types. Let's understand through an example.
In the above code, we have created a user-defined data type named 'point' that is made by combining two primitive data types of integer type named 'x' and 'y'.
Abstract data types
Abstract data types are like user-defined data types, which define the operations on the values using functions without specifying what is inside the function and how the operations are performed.
Stack ADT: Here, the stack consists of elements of the same type arranged in sequential order. The following are the operations that can be performed on the stack are:
Note: We can think of ADT as a black box that hides the user's inner structure and design of the data type.
There are multiple ways to implement an ADT. For example, a stack ADT can be implemented using arrays or linked lists.
The program which uses data structure is known as a client program, and it has access to the ADT or interface. The program that implements the data structure is known as implementation.
If someone wants to use the stack in the program, he can directly use the push and pop operations in the program without knowing its implementation details.
What is data structure?
A Data structure is a collection of different types of data on which a specific set of operations can be performed. It is a collection of different data types. It is a way of organizing the data in memory. The various operations that can be performed on a data structure are insertion, deletion, and traversal. For example, if we want to store the data of many students where each student has a student name, student id, and a mobile number. To store such big data requires complex data management, which requires a data structure comprising multiple primitive data types.
Differences between the data type and the data structure