Question:C program for swapping of two numbers using pointers 

Answer 
#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;
}
Sample output: Enter any two integers: 5 10 Before swapping: a = 5, b=10 After swapping: a = 10, b=10 

+ Report
Total Preview: 419
C program for swapping of two numbers using pointers
Copyright © 2024. Powered by Intellect Software Ltd