Thursday, May 27, 2010

Program to Find Address of Element in One Dimensional Array

#include < stdio.h >
#include < conio.h >
void main()
{
int a[10], i, badd,n,pos, eadd;
clrscr();
printf("Enter size of Array = ");
scanf("%d",&n);

printf("\n Enter Array Elements \n");
for ( i=0;i
{
    scanf("%d",&a[i]);
}

printf("Address of element = ");
scanf("%d",&pos);

//find base address and convert address in int type
badd=(int)&a;

// find the address of element
eadd=badd + sizeof(int) * pos;

printf("Base Address = %d \nSize of Data Type = %d \nAddress of Element = %d\n", badd, sizeof(int), pos);
printf("Address of element a[%d] = %d",pos,eadd);
getch();
}

No comments:

Post a Comment