Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: loop through map c++ 
Cpp :: c++ celsius to fahrenheit 
Cpp :: angle to vector2 
Cpp :: c++ edit another processes memory address 
Cpp :: erosion and dilation c++ 
Cpp :: what is difference between single inverted and double inverted in programming languages 
Cpp :: ue4 c++ array 
Cpp :: ue4 get socket location c++ 
Cpp :: every number is coming thrice except one 
Cpp :: create and write to a file c++19 
Cpp :: initialize a pair 
Cpp :: change int to string cpp 
Cpp :: climits in cpp 
Cpp :: std::tuple apply multiplier 
Cpp :: custom comparator in set of struct 
Cpp :: c++ program to add two numbers using function 
Cpp :: how to get 4 decimal places in c++ 
Cpp :: prime number program 
Cpp :: qt double en qstring 
Cpp :: using find in vector c++ 
Cpp :: separating class into header and cpp file 
Cpp :: c++ round number up 
Cpp :: cpp split string by space 
Cpp :: how to make for loop in c++ 
Cpp :: c++ switch string 
Cpp :: how to split a string into words c++ 
Cpp :: c++ switch case break 
Cpp :: string to int in c++ 
Cpp :: insert vector to end of vector c++ 
Cpp :: file open cpp 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =