C PROGRAMMING

write a c program to swap two variables using function and pointer (call by reference)

 

#include<stdio.h>
void swap(int *num1, int *num2) {
int temp;
temp = *num1;
*num1 = *num2;
*num2 = temp;
}



main() {
int num1, num2;
printf("nEnter the first number : ");
scanf("%d", &num1);
printf("nEnter the Second number : ");
scanf("%d", &num2);
swap(&num1, &num2);
printf("nFirst number : %d", num1);
printf("nSecond number : %d", num2);
getch();
}

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button