3,910 views
1 votes
1 votes
A function that  does the same operation on different data types is to be implemented using

a) macros   b) overloading  c) function templates  d) default arguments

1 Answer

3 votes
3 votes
  • Function Template enables us to define a function that works for multiple data types.
template <typename T>
int compare(T a,T b) {
	if(a < b) return -1;
	else if(a > b) return 1;
	else return 0;
}

int main() {
	int x = 2;
	int y = 3;
	printf("%d\n",compare(x,y));

	double a = 2.3;
	double b = 1.3;
	printf("%d\n",compare(a,b));
}
Answer:

Related questions

4 votes
4 votes
2 answers
1
Sanjay Sharma asked Dec 11, 2016
3,928 views
An electronic device used to connect different types of topologies having same protocol1)Repeater2)Router3)Bridge4)Switch
1 votes
1 votes
1 answer
4
sh!va asked Jul 9, 2016
1,232 views
Suppose Ethernet physical addresses are chosen at random (using true random bits). The probability that on a 1024-host network, two addresses will be the same is : 1.77 �...