0% found this document useful (0 votes)
24 views

Pointers and Functions

Useful for FIrst Year b.tech students
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Pointers and Functions

Useful for FIrst Year b.tech students
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Pointers and functions

/* sorting of array in descending order using functions and pointers


It returns pointer as a return value */

#include<stdio.h>
#include<conio.h>

int *sort(int[],int); // function declaration


int a[10],i,j,n,t,*p;

void main()
{
clrscr();
printf("Enter the size of the array \n");
scanf("%d",&n);
printf("Enter array elements");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
p=sort(a,n); // function call
printf("\nThe sorted array is:");
for(i=0;i<n;i++)
{
printf("\n%d",*(p+i));
}

int *sort(int a[],int n) // function definition


{
for(i=0;i<=n-2;i++)
{
for(j=i+1;j<=n-1;j++)
{
if(a[i]<a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
return a;
}

Y. AROCKIA RAJ, AP / CSE PSNA COLLEGE OF ENGINEERING AND TECHNOLOGY Page 16

You might also like