arr++ is not working but i want to know why?
arr stores the base address that is &arr[0] therefore, arr always points to the starting position of the array and can't be changed. that's the reason why arr++ is invalid and doesn't work.
Solution:
you can instead use arr with the help of * (referencing operator) operator to print the array elements
for(i=0;i<5;i++)
{
printf("%d\n",*(arr+i));
//pointer arithmetic *(arr+i)=*(&arr[0]+i*sizeof(data_type_of_arr))
}
here, pointer arithmetic is helpful to understand
or else, in order to print the data instead use the index i this way :
for(i=0;i<5;i++)
{
printf("%d\n",arr[i]);
}
One more way to do it is to consider a new pointer to &arr[0] and increment.
int *p=&arr[0];
for(i=0;i<5;i++)
{
printf("%d\n",*p);
p++;
//pointer arithmetic *(p)=*((&p)+1*sizeof(data_type_of_arr))
//NOTE: address of p updates for every iteration
}
For further reading on pointer arithmetic : here