C Program to Swap two Numbers Using Function and Pass By Reference
#include<stdio.h>
#include<conio.h>
void swap(int *num1,int *num2);
void main()
{
int x,y;
printf("\nEnter First number : ");
scanf("%d",&x);
printf("\nEnter Second number : ");
scanf("%d",&y);
printf("\nBefore Swaping x = %d and y = %d",x,y);
swap(&x,&y); // Function Call - Pass By Reference
printf("\n After Swaping x = %d and y = %d",x,y);
getch();
}
//----------------------------------------------
void swap(int *num1,int *num2)
{
int temp;
temp = *num1;
*num1 = *num2;
*num2 = temp;
}
Output :
Enter First number : 12
Enter Second number : 21
Before Swaping x = 12 and y = 21
After Swaping x = 21 and y = 12
0 Comments:
Post a Comment
Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email