Program in which function is passed address of two variables and alter its contents.
// Program in which function is passed address of two variables and alter its contents.
#include<stdio.h>
void alter(int* , int*);
int main() {
int a, b;
printf("Enter two numbers : ");
scanf("%d%d",&a, &b);
printf("Before swapping a = %d, b = %d", a, b);
alter(&a, &b);
printf("\nAfter swapping a = %d, b = %d", a, b);
return 0;
}
void alter(int*a , int*b){
int t;
t=*a;
*a=*b;
*b=t;
}
Output :
Enter two numbers : 5 7
Before swapping a = 5, b = 7
After swapping a = 7, b = 5
No comments:
Post a Comment