/*example of pass by address*/
#include<stdio.h>
#include<stdlib.h>
void swap (int *,int *);
int main()
{
int a=5,b=9;
printf("before swapping a=%d and b=%d",a,b);
swap(&a,&b);
printf("\n after swapping a=%d and b=%d",a,b);
system ("pause");
return 0;
}
void swap (int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
#include<stdio.h>
#include<stdlib.h>
void swap (int *,int *);
int main()
{
int a=5,b=9;
printf("before swapping a=%d and b=%d",a,b);
swap(&a,&b);
printf("\n after swapping a=%d and b=%d",a,b);
system ("pause");
return 0;
}
void swap (int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
No comments:
Post a Comment