display(arr,5);//WE HAVE passed base address & no.of times of loop execution
return 0;
}
int display(int *m,int x)
{
int i;
for(i=0;i<=x-1;i++)//x=5 so i=0 to i=4 means loop will consider to operate 5 times
{
printf("arr[%d]=%d\n",i,*m);//*m representing values of array elements as m++ is incrementing pointer
m++;
}
return 0;
}
Although it is not a better idea to increment pointer itself we may do same thing as::::---------
#include<stdio.h>
int display(int*,int);
int main()
{
int*j;
int arr[5]={55,22,33,555,65};
display(arr,5);
return 0;
}
int display(int *m,int x)
{
int i;
for(i=0;i<=x-1;i++)
{
printf("arr[%d]=%d\n",i,*(m+i));//i is incrementing in loop & no matter that for int type i weather int type or char type array adding to incrementing address.....if array is of int type ,one increment of i will increments its address 4bytes in 32 bit os...or for char type array...++ment of i will ++ment address by1byte....
}
return 0;
}
Advantage of doing using variable i is this ,that base address of array will always be preserved in arr.......or by this base address array may be acquired anytime bcz this base address is a key for us to get whole array.....