Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

#include<stdio.

h>
#include<conio.h>
int add(int, int); /*declaration */
main()
{
int a,b,c; /*declaration*/
printf(“Enter the elememts”); /*statement*/
scanf(“%d%d”,&a,&b); /*input*/
c=add(a,b); /*function call*/
printf(“%d”,c); /*display*/
}
int add(int x, int y) /* definition*/
{ int z;
z=x+y;
return z;
}
structure
struct st
{int a;
float b;
};
Struct st;

Primitive data structures are integers, real numbers, characters and pointers and
their corresponding storage representation. Non primitive data structures can
be classified as arrays, lists and files. An array is ordered set which consists of a
fixed number of objects.
int a[10];
a[0] a[1] A[9]
1000 1002 1004 1006 1008 1010 1012 1014 1016 1018
a[0]……………………………………………………………………………………………………….a[n-1]
for storing n numbers.
…………
int a[100], i, n;
for(i=0;i<n;i++) /*i index */
scanf(“%d”, &a[i]);
for(i=0;i<n;i++)
printf(“%d”, a[i]);
……..


a[0,0] a[0,1] A[0,2]
A[1,0] A[1,1] A[1,2]
A[2,0] A[2,1] A[2,2]

2D-array

a[0,0] a[0,1] A[0,2]
A[1,0] A[1,1] A[1,2]
A[2,0] A[2,1] A[2,2]

A list on the other hand is an ordered set consisting of a variable number of
elements to which insertions and deletions can be made.

A file is typically a large list that is stored in the external memory of a computer.

The simplest data structures that makes use of computed address to locate it’s
elements is the one dimensional array we have called a vector. Normally a
number of memory locations is sequentially allocated to the vector.

A vector size is fixed and therefore requires a fixed number of memory
locations.
In general, a vector with a subscript lower bound of one can be represented
diagrammatically as in figure 1, where L0 is the address of the first word
allocated to the first element of a, and c represents the number of words
allocated to each element. The address of Ai is given by the following equation:

lOC( Ai )= L0 + c* (i-1)

You might also like