Asked By:
Ramesh Chinta
in
C Language
-
125 days ago
manohar's Answer
Memory allocation is of 2 types. Static and Dynamic.
If the C string variable is defined as array. for example "char str[1024];"
The memory is allocated by during program load. The size of memory can not be modified (neither increased nor decreased) and it is fixed.
Where as another type of allocation is a runtime allocation which is usually refered as Dynamic memory allocation. libc provides allocation functions for this purpose. They are malloc, calloc, realloc, free().
Using malloc one can allocate memory dynamically whenever it is required and can be released using free() call.
For example.
char *str=NULL
str=(char*)malloc(1024)
This will allocate 1024 bytes and returns the pointer which 'str' will point to.
Let me know if you require more details.
Answered
123 days ago |
Read Comments (1)
Read answer