void sort(int *ptr, int n) {
int i,j,tmp;
for (i=0;i<n;i++)
for (j=i;j<n;j++)
if (ptr[i] > ptr[j])
{
tmp=ptr[i];
ptr[i]=ptr[j];
ptr[j]=tmp;
}
}
AND
void sort(int *ptr, int n) {
int i,j,tmp;
for (i=0;i<n;i++)
for (j=i;j<n;j++)
if (*(ptr+i) > *(ptr+j))
{
tmp=*(ptr+i);
*(ptr + i) = *(ptr + j);
*(ptr + j)=tmp;
}
}
It has the same output. Both works. I've seen people using both, although obviously the first one seems more natural and intuitive than the second. Is there any problems whatsoever in using the first one over the second? Also, what are the main differences between them, if any?