In this program, we will understand how to write a C program to swap two numbers using pointers and functions. How to swap two numbers using a call by reference. Logic to swap two numbers using pointers in a C program.
First of all, imagine the output screen.
OUTPUT
Enter two number for swapping: 5
8
a=5 and b=8
after swapping
a=8 and b=5
You must have this knowledge.basic c, function, pointer
Program logic
This is a call by reference program. In which we will be swapping with the help of the pointer.
Declare two variables int type then store the data in it.
call Xchange function and passing address num1 and num2
after that xchange function arguments receive the address.
declare temporarily variable in a xchange function.
temporarily variable assign *ptr1 value after that *ptr1 value asign *ptr2 value and then
*ptr2 assign temporarily variable
now print your result.
c program swap two numbers using pointers call by reference
Now next you are, write your code in the comment below.😊
0 Comments:
Post a Comment
Please do not enter any spam link in the comment box.