Vision and dreams are the blueprints of soul and achievements.
-Mohammed Ahmed F

Program to swap two numbers using POINTERS

#include<stdio.h>

int main(){

    int a,b;
    int *ptra,*ptrb;
    int *temp;

    printf("Enter any two integers: ");
    scanf("%d%d",&a,&b);

    printf("Before swapping: a = %d, b=%d",a,b);

    ptra = &a;
    ptrb = &b;

     temp = ptra;
    *ptra = *ptrb;
    *ptrb = *temp;

    printf("\nAfter swapping: a = %d, b=%d",a,b);
    return 0;
}

OUTPUT:
Enter any two integers: 8
3
Before swapping: a = 8, b=3
After swapping: a = 3, b=8

Share this

Related Posts

Dear User,

Thank you for your comment. Hope you like this blog. Kindly share us on Social Media so others can be updated.

-Chief Administrative Officer.

Note: only a member of this blog may post a comment.