Coupon Accepted Successfully!


Working Of Function Templates

In the last few examples, we have learned how to write a function template that works with all data types. After compilation, the compiler cannot guess with which type of data the template function will work. When the template function is called at that moment, from the type of argument passed to the template function, the compiler identifies the data type. Then, every argument of template type is replaced with the identified data type; this process is called instantiating. Thus, according to different data types, respective versions of the template function are created. Though the template function is compatible for all data types, it will not save any memory. When template functions are used, four versions of functions can be used. The data types int, char, float, and double are created. The programmer need not write separate functions for each data type.

Test Your Skills Now!
Take a Quiz now
Reviewer Name