Use pointers to replace the value of two variables
Hey guys once again welcome to the Decoders blog, I hope you all are doing well and today I'm present with another logic but this time with something different it is a C logic which will replace the values of two variables using the pointers
Here's the code which you can go through...........
#include<stdio.h>
int main()
{
int a,b;
int *ptra,*ptrb;
//Using pointers to replace the two variables
printf("Enter the values of a and b:\n");
scanf("%d%d",&a,&b);
printf("The value of a is %d\n",a);
printf("The value of b is %d\n",b);
ptra=&a;
ptrb=&b;
printf("The value of a is %d\n",*ptrb);
printf("The value of b is %d",*ptra);
}
Comments
Post a Comment