/*
It is one of the best example to handle pointers.
Here in this program, I am assuming the pointer as array and operating it as like array.
The array variable are nothing but the pointers which are holding the initial address of the array of specific size.
*/
#include<stdio.h>
int * arraySorting(int *arr, int size) // Bubble sort function
{
int i,j,temp;
for(i=0; i<size-1; i++) {
for(j=i+1; j<size; j++) {
if(arr[i] > arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
return arr;
}
int main()
{
int arr[10] = {5,2,3,0,1,6,5,2,4,7}; // Instead of static initialization, you can initialize dynamically.
int size = 10;
int i = 0;
arraySorting(arr, size);
for(i = 0; i<size; i++) {
printf("%d\t", arr[i]);
}
return 0;
}
No comments:
Post a Comment