In this program we will clear the concept of template in c++
//Code starts
#include<iostream>
#include<conio.h>
using namespace std;
template <class T>
void abc(T* array,int size)
{
for(int i=0;i<size;i++)
{
cout<<array[i]<<",";
}
}
int main()
{
float ar[5]= {0.3,2.5,6.3,5.9,6.6};
int arr[5];
for(int i=0;i<5;i++)
{
cout<<"Enter integer : ";
cin>>arr[i];
}
abc(ar,5);
cout<<endl;
abc(arr,5);
getch();
}
//Code ends
OUTPUT:
//Code starts
#include<iostream>
#include<conio.h>
using namespace std;
template <class T>
void abc(T* array,int size)
{
for(int i=0;i<size;i++)
{
cout<<array[i]<<",";
}
}
int main()
{
float ar[5]= {0.3,2.5,6.3,5.9,6.6};
int arr[5];
for(int i=0;i<5;i++)
{
cout<<"Enter integer : ";
cin>>arr[i];
}
abc(ar,5);
cout<<endl;
abc(arr,5);
getch();
}
//Code ends
OUTPUT:
0 comments:
Post a Comment