Answers for "write a custom swap function c++"

C++
0

swap using Function template in c++

#include <bits/stdc++.h>
using namespace std;
template<class T , class T1>
void excha(T &a , T1 &b){
    T temp = a;
    a = b;
    b = temp;
    
}
int main(){
    // int a , b;
    // cout<<"Enter the value of a and B "<<endl;
    // cin>>a>>b;
    // excha(a,b);
    // cout<<a<<" "<<b<<endl;

    // cout<<endl;

    // float a , b;
    // cout<<"Enter the value of a and B "<<endl;
    // cin>>a>>b;
    // excha(a,b);
    // cout<<a<<" "<<b<<endl;

    cout<<endl;

    float a ;int b;
    cout<<"Enter the value of a and B "<<endl;
    cin>>a;
    cin>>b;
    excha(a,b);
    cout<<a<<" "<<b<<endl;

    return 0;
}
Posted by: Guest on September-11-2021
0

c++ swap function

int main()
{
	int a = 5;
	int b = 10;
  
	swap(a, b);
  
	cout << "a = " << a << endl;
	cout << "b = " << b << endl;
}
Posted by: Guest on May-08-2021

Browse Popular Code Answers by Language