Abstract Data Types

Sometimes primitive data types are not sufficient to store complex data in that case programmer need to define their own which is called Abstract Data Types (ADT).  Programmers need to define the mechanism how the data is being stored in memory and what kind of operations can be performed over them.

Like if you need to store 100 customer information then primitive data type wouldn’t help you because in primitive data type we can store only single value or group of same type of values using array. But here’s all information are of different data types. That’s why need of abstract data type here.

  • Custom ID
  • Custom Name
  • Address Line 1
  • Address Line 2
  • Registration Date

and lots more.

To keep those information you need to create your own data type so that you can easily store information. In C language struct keyword is used to create abstract data type.

Syntax

 struct NameOfStructure{
  //data members

 };

You can access member of a structure by dot operator(.).

Example of ADT

 #include<stdio.h>
 #include<conio.h>
 
 struct customer{
   int id;
   char name[20];
   char addressLine1[100];
   char addressLine1[100];
 }

void main(){
  clrscr();
  struct customer c1;
  c1.id = 100;
  c1.name= {'R','A','J'};
  c1.addressLine1= {'A','N','A','N','D','','V','I','H','R'};
  c1.addressLine2= {'D','E','L','H','I'};

  printf("\nID=%d",c1.id);
  printf("\nName=%d",c1.name);
  printf("\nAddress Line1=");
  puts(c1.addressLine1);
  printf("\nAddress Line2=");
  puts(c1.addressLine2);
  getch();
}

Output

 ID=100
 Name=RAJ
 Address Line1=ANAND VIHAR 
 Address Line2=DELHI

Leave a Reply