CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Our Services
Get 9,000 Interview Questions & Answers in an eBook.




Get it now !!
Send your Resume to 6000 Companies

Search Interview Questions

Question: What is a template?

Answer: Templates allow to create generic functions that admit any data type as parameters and return value<br>without having to overload the function with all the possible data types. Until certain point they fulfill<br>the functionality of a macro. Its prototype is any of the two following ones:<br><br>template <class indetifier> function_declaration; template <typename indetifier><br>function_declaration;<br><br>The only difference between both prototypes is the use of keyword class or typename, its use is<br>indistinct since both expressions have exactly the same meaning and behave exactly the same way.



Category Templates in C++ Interview Questions & Answers - Exam Mode / Learning Mode
Rating (0.4) By 5899 users
Added on 10/22/2009
Views 69483
Rate it!
Question: What is a template?
Answer:

Templates allow to create generic functions that admit any data type as parameters and return value<br>without having to overload the function with all the possible data types. Until certain point they fulfill<br>the functionality of a macro. Its prototype is any of the two following ones:<br><br>template <class indetifier> function_declaration; template <typename indetifier><br>function_declaration;<br><br>The only difference between both prototypes is the use of keyword class or typename, its use is<br>indistinct since both expressions have exactly the same meaning and behave exactly the same way. Source: CoolInterview.com


when we have diff function but having/implementing same algorithm the we can use template for that like-<br><br>we want to swap int ,char , float.<br>we need not to define 3 function we can implement it by using templete<br><br>function defination <br>template <class T> <br>return_type fn_name(argument name)<br>{<br>body<br>} Source: CoolInterview.com

Answered by: manohar | Date: 7/26/2008 | Contact manohar Contact manohar

There are two differences. First, is in the number of arguments. Malloc() takes a single argument (memory required in bytes), while calloc() needs two arguments (number of variables to allocate memory, size in bytes of a single variable). Secondly, malloc() does not initialize the memory allocated, while calloc() initializes the allocated memory to ZERO. <br><br> Source: CoolInterview.com

Answered by: Pavitra Palacharla | Date: 1/27/2009 | Contact Pavitra Palacharla Contact Pavitra Palacharla

Template is used to implement the concept of generic programming.<br>Templates allow us to generate a family of classes or a family of functions to handle different data types. Source: CoolInterview.com

Answered by: Pavitra | Date: 1/27/2009 | Contact Pavitra Contact Pavitra

Template is the method of writing single fun or class for the family of fun or class in generic manner Source: CoolInterview.com

Answered by: D Gayathri | Date: 7/15/2009 | Contact D Gayathri Contact D Gayathri

?a template is a model that serves as a pattern for creating similar objects?. One type of template that is very easy to understand is that of a stencil. A stencil is an object (eg. a piece of cardboard) with a shape cut out of it (eg. the letter J). By placing the stencil on top of another object, then spraying paint through the hole, you can very quickly produce stenciled patterns in many different colors! Note that you only need to create a given stencil once ? you can then use it as many times as you like to create stenciled patterns in whatever color(s) you like. Even better, you don?t have to decide the color of the stenciled pattern you want to create until you decide to actually use the stencil. Source: CoolInterview.com

Answered by: ajay bob | Date: 8/11/2009 | Contact ajay bob Contact ajay bob

templates allows us to write one function or class that works for different data types.By using templates,we can design a single class or function that operates on many datatypes,instead of having to create separate class or function for each type. Source: CoolInterview.com

Answered by: seema | Date: 9/21/2009 | Contact seema Contact seema

templet is just like a poster which display the all facility which is given by authore and it used by second & third person like main funcation & user Source: CoolInterview.com

Answered by: subhash | Date: 11/10/2009 | Contact subhash Contact subhash

Template is a new concept that enable us to create generic classes and functions thus providing a way for generic programming.<br>Generic programming is an approach where generic datatypes are used as parameters in algorithms so that they can work for a variety of data types and data structures. Source: CoolInterview.com

Answered by: hema | Date: 1/30/2010 | Contact hema Contact hema


If you have the better answer, then send it to us. We will display your answer after the approval

Rules to Post Answers in CoolInterview.com:-

  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.

Post your answer here

Inform me about updated answers to this question.
Related Questions
View Answer
What is namespace?
View Answer

Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

View All Templates in C++ Interview Questions & Answers - Exam Mode / Learning Mode




India News Network
Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal
Cache = 0.0625 Seconds