Concept of a Data Type



Data items are the physical symbols that represent information in the computer system. A computer program operates on data and produces an output. In a computer programming language (high-level programming language) each data item must be of a specific type. The data type determines how the data items will be represented in the computer and what types of operations the computer will be able to perform on them. In other words a data type is a term which refers to the kinds of the data that variables may hold in a programming language. With every programming language there is a set of built-in data types. Some of the standard data types in ‘C’ are: integer, double, float and character.


When we say it is of type integer or real or character then it means that we are talking about the set of values and the set of operations applicable those values. In other words to define a type, the set of values and the set of operations are defined. Thus as far as the integer type is concerned, the operations such as addition, subtraction, multiplication etc. are defined. These operations are defined to be binary, that is we need two integer operands in order to perform addition or subtraction or multiplication and so on. But if we use character data type then two variables of character data type can not be added or subtracted because these operations are not defined on character data type.


Another main point to note here is that we have to define each type of data that we will use in our program. Of course almost every programming language support built-in data types, they are not enough for most of the practical applications, that’s why we need structured data types.


Structured Data Types



Programming languages, such as Pascal or C, however, provide tools such as arrays, structure, files, and pointers, with which new data types can be built. Such data types are called as structured data types. A structure data type is made up of several components each of which are either an atomic type (types such as integer, real and character are called atomic types because we think of their values as single entities only) or of another structure type. In C. this can be accomplished by defining a struct. However, just by defining a structured data type, the operations applicable to variables of that type can not be specified.


Abstract Data Types



We know that a basic data type is a collection of values and a set of operations on those values. In the same way the term abstract data type (ADT) refers to a programmer defined data type together with a set of operations that an be performed on that data. It is called abstract just to distinguish it from basic built-in data types such as int, char, and double. In other words the definition of an ADT consists of two main points – the internal representation of the ADT’s data and the functions to manipulate this data.


In C we can define an ADT by using the keywords – typedef and struct and defining the functions thus data abstraction. But in C++ we have much better facilities, using class, for defining and using ADTs. And it is totally the programmer’s duty to use the class mechanism in such a way that it does, in fact, represents an ADT. This process of defining an abstract data type together with the principles of data hiding is called data abstraction, one of the basic concepts underlying OOP (Object Oriented Programming). You will be surprised to even know that most experts agree that OOP involves defining ADT representing complex real-world.


For example, consider the list abstract data type. A list of element of type T is a finite sequence of elements of T together with the possible operations, such as:



1. initialize the list to be empty
2. adding new elements to the list, provided that list is not full
3. deleting elements from the list, provided that list is not empty
4. determine the length of the list
5. determine whether the list is empty or not
6. determine whether the list is full or not
7. replacing an element in the list, provided that list is not empty



Here the programmer is not concerned with how a list is represented and how the above mentioned operations are implemented. We only need to know that we have a list whose elements are of given type T, and what can we do with the list.  Similarly we can consider the stack abstract data type. A stack of element of type T is a finite sequence of elements of T together with the possible operations, such as:



1. initialize the stack to be empty
2. adding new elements to the stack, provided that stack is not full
3. deleting elements from the stack, provided that stack is not empty
4. retrieving the topmost element from the stack, provided that stack is not empty
5. determine whether the stack is empty or not
6. determine whether the stack is full or not



Again the stack abstract data type make no mention of the way in which it is to be implemented. We only need to know that we have a stack whose elements are of given type T, and what can we do with the stack. It is to emphasize again that defining an ADT implies a description of the way in which the elements are related to each other and a set of operations that can be performed on elements of the abstract data type.

 


Like it on Facebook, Tweet it or share this article on other bookmarking websites.

No comments