Link Between Array and Pointer


#include

void main()
{

const int size = 5;

int list[size] = {2,1,3,7,8};

int* plist = list;

// print memory address of array elements
for(int i = 0; i < size;i++)
{
printf("list[%d] is in %d\n",i,&list[i]);

}

// accessing array elements using pointer
for(i = 0; i < size;i++)
{
printf("list[%d] = %d\n",i,*plist);

/* increase memory address of pointer so it go to the next
element of the array */
plist++;
}

}

No comments:

Post a Comment