Problem:- C++ program to swap two numbers using pointers or Swapping two variable using pointers or C++ program to swap two numbers using call by value or C Program to Swap Two Numbers / Variables using Pointer or Simple Example Program for Swap Numbers Using Pointers In C++ or swap 2 numbers using pointers in C or C++ Program to Swap Two Numbers or C++ function call by pointer or C Program to Swapping Two Numbers Using a Temporary Variable or C Program to Swapping Two Numbers Using Bitwise Operators or C++ pointers declaring, passing pointer to function or C program to swap two numbers or C Program to Swap Two Numbers Using Pointer or program to swap two numbers using pointers and functions or write a code to swap two numbers using reference in c++.
Explanation:- Swapping the two number is very easy we have to take a two number entered by user and pass the both two number in function by reference or pass by value here we are passing the both number by reference(passing address of variable) and in function we put the swapping condition in function as you can see in the below program. after the swapping the number either we can return the result to function or we can directly print the swapped numbers in function. In this swapping method (call by reference) anything changed in the value will also affect the actual parameters but here we print the swapped value in the same function But it is not necessary we can directly print the value in the main function cause we pass the value through call by reference not call by value.
Extreme Recommended:- If this post is beneficial for you and you want Updates for New post then please like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.
Solution:-
#include<bits/stdc++.h>
using namespace std;
void swap(int&, int&);
int main()
{
/*visit - programmingwithbasics.com*/
int first, second;
cout<<"Enter The Two Value \n";
cin>>first>>second;
cout << "\nBefore Swapping Values Are\n" << endl;
cout<<"First Value is = "<<first<<endl;
cout<<"Second Value is = "<<second<<endl;
swap(first, second);
return 0;
}
void swap(int &first, int &second)
{
int temp;
temp = first;
first = second;
second = temp;
cout << "\n\nAfter Swapping Values Are\n" << endl;
cout<<"First Value is = "<<first<<endl;
cout<<"Second Value is = "<<second<<endl;
}
Output:-
1. C++ Program To Check Character Is Uppercase, Lowercase Alphabet Or A Digit Or A Special Symbol
2. C++ Program To Find Greatest Among Three Numbers
3. C++ Program To Check Number Is Armstrong Or Not Using If/Else Statements
4. C++ Program To Find Character Is Vowel Or Not Using If/Else Statements
5. C++ Program To Check Number Is Even Or Odd Using If/Else Statements
6. C++ Program To Check Number Is Prime Or Not Using If/Else Statements
7. C++ Program Convert Decimal Number To Binary Number Using Loop
8. C++ Program To Print The Fibonacci Series Up to Given Number Of Terms
9. C++ Program to Sort Elements in Lexicographical Order (Dictionary Order) Using For Loop
10. C++ Program To Find Whether A Number Is Palindrome Or Not
8. C++ Program To Print The Fibonacci Series Up to Given Number Of Terms
9. C++ Program to Sort Elements in Lexicographical Order (Dictionary Order) Using For Loop
10. C++ Program To Find Whether A Number Is Palindrome Or Not
0 Comments: