54. Swap Two Pointers Using Double Pointers

Back To All Submissions
Previous Submission
Next Submission

Code

#include<stdio.h>

// Function to swap pointers
void swapPointers(int **pp1, int **pp2)
{
    int *temp;

    temp = *pp1;
    *pp1 = *pp2;
    *pp2 = temp;
}

int main()
{
    int a, b;

    scanf("%d %d", &a, &b);

    int *ptr1 = &a;
    int *ptr2 = &b;

    swapPointers(&ptr1, &ptr2);

    printf("%d ", *ptr1);
    printf("%d", *ptr2);

    return 0;
}

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote