sorting of array using pointer in c

int main(){
   int  i,j,temp1,temp2;
   int arr[8]={5,3,0,2,12,1,33,2};
   int *ptr;
   for(i=0;i<7;i++){
     for(j=0;j<7-i;j++){
if(*(arr+j)>*(arr+j+1)){
        ptr=arr+j;
        temp1=*ptr++;
        temp2=*ptr;
        *ptr--=temp1;
        *ptr=temp2;
}
      }
   }

   for(i=0;i<8;i++)
     printf(" %d",arr[i]);
}

Output: 0 1 2 2 3 5 12 33

Pointer to function
Pointer to array of function
Pointer to array of string
Pointer to structure
pointer to union
Multi level pointer
Pointer to array of pointer to string
Pointer to three dimentional array
Pointer to two dimensional array
Sorting of array using pointer
Pointer to array of array
Pointer to array of union
Pointer to array of structure
Pointer to array of character
Pointer to array of integer
C tutorial

5 comments:

Mohini said...

pls provide the explanation..........

Vishnu Menon said...

pls ..i also need the explanation..

shoaib said...

pls can u give the explanation??????????

Harsh said...

Its simple...

first v take an array with some values(may be entered by the user_).
then v compare the 2 neighbouring terms using pointer.
then if they are not properly arranged v swap them. As here v use pointers it becomes necessary to use 2 temporary variables to point the locations of 2 terms.
and the rest is simple

gayathri said...

its very helpful and thank u. i think
its a keywords of dictionary c language...................