0
what is template functions ? Explain dynamic memory allocation.
4 odpowiedzi
+ 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.
+ 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
+ 4
Later we can save the data from the heap to any normal array
+ 3
Vectors , etc use dynamic memory first to recieve data and adjust size at runtime...