In this article I would like to share with you a sample program that will swap the two numbers using Pointers in C.
programming projects , thesis and capstone projects, IT consulting
work, computer tutorials and web development work kindly contact me in the following email address for further details. If you want to advertise in my website kindly contact me also in my email address also. Thank you.
I am currently accepting programming work, it project, school
programming projects , thesis and capstone projects, IT consulting
work, computer tutorials and web development work kindly contact me in the following email address for further details. If you want to advertise in my website kindly contact me also in my email address also. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.
Program Listing
swap.c
#include <stdio.h>
int swap(int *x, int *y, int t);
main {
int x=0,y=0,t=0;
x=20; y=30; t=40;
printf(“\n The original value of x: %d”,x);
printf(“\n The original value of y: %d”,y);
printf(“\n The original value of t: %d”,t);
printf(“\nTheir values after calling the function and”);
swap(&x,&y,t);
printf(“\ntheir effect when passed by reference/pointers”);
printf(“\n x+1 = %d”,x+1);
printf(“\n y+1 = %d”,y+1);
printf(“\n t+1 = %d”,t+1);
getch();
}
int swap(int *x, int *y, int t)
{
t = *x;
*x = *y;
*y = t;
}
No comments:
Post a Comment