#include <stdio.h>
void swap(int *p, int *q)
{
int *t;
*t=*p;
*p=*q;
*q=*t;
printf("a=%d b=%d\n",*p,*q);
}
int main(void)
{
int a=5;
int b=10;
swap(&a,&b);
printf("a=%d b=%d",a,b);
return 0;
}
this program working right but why not second code swap the value of a and b
#include <stdio.h>
void swap(int *p, int *q)
{
int *t;
t=p;
p=q;
q=t;
printf("a=%d b=%d\n",*p,*q);
}
int main(void)
{
int a=5;
int b=10;
swap(&a,&b);
printf("a=%d b=%d",a,b);
return 0;
}