C Programming Code Examples C > Arrays and Matrices Code Examples Program to Accept an Array & Swap Elements using Pointers Program to Accept an Array & Swap Elements using Pointers This C Program accepts array & swap elements using pointers. The program is used to swap the elements of a given array and swapping is done using pointers. /* C program to accept an array of 10 elements and swap 3rd element with 4th element using pointers and display the results. */ #include <stdio.h> void swap34(float *ptr1, float *ptr2); void main() { float x[10]; int j, n; printf("How many Elements...\n"); scanf("%d", &n); printf("Enter Elements one by one\n"); for (j = 0; j < n; j++) { scanf("%f", x + j); } /* Function call:Interchanging 3rd element by 4th */ swap34(x + 2, x + 3); printf("\nResultant Array...\n"); for (j = 0; j < n; j++) { printf("X[%d] = %f\n", j, x[j]); } } /* Function to swap the 3rd element with the 4th element in the array */ void swap34(float *ptr1, float *ptr2 ) { float temp; temp = *ptr1; *ptr1 = *ptr2; *ptr2 = temp; }