# Bubble Sort In C Using Pointers Program

Bubble Sort In C Using Pointers. If you are looking for a bubble sort program in C with pointers example, this C programming tutorial will help you to learn how to write a program for bubble sort in C. Just go through this C programming example to learn about bubble sort, we are sure that you will be able to write a C program for bubble sort using pointers.

## Bubble Sort in C Using Pointers

### What is Bubble Sort?

Bubble Sort in C is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order.

### Bubble Sort Example

This below image illustrates what is Bubble Sort in C.

## Bubble Sort in C Using Pointers

Learn how to write a  bubble sort in c using pointers. Writing a Bubble Sort C Program can be done using various techniques like an array, pointers, recursionfunction but here in this program, we show how to write a bubble sort program in c using pointers in a proper way.

### Bubble Sort Program in C Using Pointers – Source Code

You can copy paste the below bubble sort program in c compiler to check how the source code work. Or write your own Bubble Sort in C Using Pointers with the help of this below c program for bubble sort.

```/* BUBBLE SORT PROGRAM IN C USING POINTERS - BUBBLESORT.C */

#include<stdio.h>

int *a,i,j,item;

void main()

{

void sort(),display(); //function declarations

int i;

clrscr();

printf("\n Enter the number of elements in the first array\n");

scanf("%d",&item); //reding elements from user

printf("\n Enter %d numbers\n",item);

for(i=0;i<item;++i)

scanf("%d",&a[i]);

sort(); //calling sort function to perform bubble sort

display(); //calling display function to display elements

}

void sort() //sort function to sort elements

{

int swap=1,*temp;

for(i=0;i<item && swap==1;++i)

{

swap=0;

for(j=0;j<item-(i+1);++j)

if (a[j]>a[j+1])
{

temp=a[j];

a[j]=a[j+1];

a[j+1]=temp;

swap=1;
}

}

}

void display() //display function

{

printf("\n Sorted elements are:\n");

for(i=0;i<item;++i)

printf("%d\n",a[i]);

getch();

}```

#### C PROGRAM FOR BUBBLE SORT – OUTPUT

After you compile and run the above bubble sort program in c using pointers, your C compiler asks you to enter elements for bubble sort. After you enter elements, the program will be executed and give output.