C , Language , Memory Management , malloc , Calloc
Abstract
Manual memory management for dynamic memory allocation in the C programming language is what is referred to as dynamic memory allocation.
There are two ways of allocating memory allocated in C, ie, by declaring the variables and by explicitly requesting space.
We have discussed variable declaration in other lectures, but here we will describe requesting dynamic memory allocation and memory management.
Space is allocated for a pointer by C whenever a pointer is declared.
For example: char *p;
Four consecutive bytes in memory are allocated which are associated with the variable p. Pointer to char is declared to be the type of pointer p. However, initialization of memory location does not happen, so it may contain garbage.Initialising the pointer at the time it is declared is usually a good idea. Its function is to reduce the chances of a random value in p to be used as a memory address. A pointer must be pointing to a valid area of memory before we can actually use it. The function malloc is used to request a pointer to a block of memory and calloc is used to request an array of zero-value initialized blocks.
Article Details
Unique Paper ID: 142754
Publication Volume & Issue: Volume 2, Issue 6
Page(s): 257 - 258
Article Preview & Download
Share This Article
Conference Alert
NCSST-2023
AICTE Sponsored National Conference on Smart Systems and Technologies
Last Date: 25th November 2023
SWEC- Management
LATEST INNOVATION’S AND FUTURE TRENDS IN MANAGEMENT