WAP to traverse a Linear Array.


#include<conio.h>
# include<stdio.h>

void memory(int *, int, int);
void memory1(char *, int, int);

void main()
{
int a[12] = {
99,88,77,66,55,44,33,22,11,100,200,300 };
char b[] = {
'A','B','C','D','E','F','G','H','I','J','K',
 'L','M','N','O','P','Q','R','S','T','U','V',

 'W','X','Y','Z' };
int d=0, e=11;
memory(a,d,e);
d = 0;
e = 25;
memory1(b,d,e);
}

void memory1(char b[], int x, int y)
{
char *pointer;
int counter;
pointer =&b[0];

for(counter = x; counter<=y; counter++)
{
printf("\n Element at location: 0x%x is %d", &b[counter], b[counter]);
}
printf("\n Array size = %d", &b[counter-1] - &b[0] + 1);
}

void memory(int a[], int x, int y)
{
int counter;

for(counter = x; counter<=y; counter++)
{
printf("\n Element at location: 0x%x is %d", &a[counter], a[counter]);
}
printf("\n Array size = %d ", &a[counter-1] - &a[0] + 1);
}

Comments