0

what is template functions ? Explain dynamic memory allocation.

9th Jan 2017, 7:17 AM
munish rastogi
munish rastogi - avatar
4 ответов
+ 4
Template functions are functions created using a template class or typename. Unlike normal functions, template functipns can be used for any existing data types as well as classes. Eg - template<typename/class Mytype> Mytype Max(Mytype a, Mytype b) {a>b?return a:return b;} Now Max() can be used for int, double, char, float and even arrays! All we have to do is create some arguments which we want to use with our preffered data type, and use the function with those.
24th Jan 2017, 12:40 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 4
Dynamic Memory is the memory used by the program at runtime. Most of the times, one is not aware of how much memory he will end up using, like in cases where we need the size of a file, etc. The main data types for our aid are arrays, but they must be sized before runtime. So to manage memory, we use dynamic menory and save all unknowns into it
24th Jan 2017, 12:45 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 4
Later we can save the data from the heap to any normal array
24th Jan 2017, 12:45 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 3
Vectors , etc use dynamic memory first to recieve data and adjust size at runtime...
24th Jan 2017, 12:46 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar