SDLC
Difference between Primary and Secondary Memory
What is Memory? Memory is very much like our brain as it is used to store data and instructions. Computer...
The malloc() function stands for memory allocation. It is a function which is used to allocate a block of memory dynamically. It reserves memory space of specified size and returns the null pointer pointing to the memory location. The pointer returned is usually of type void. It means that we can assign malloc function to any pointer.
Syntax
ptr = (cast_type *) malloc (byte_size);
Here,
Example: ptr = (int *) malloc (50)
When this statement is successfully executed, a memory space of 50 bytes is reserved. The address of the first byte of reserved space is assigned to the pointer ptr of type int.
Consider another example of malloc implementation:
#include <stdlib.h>
int main(){
int *ptr;
ptr = malloc(15 * sizeof(*ptr)); /* a block of 15 integers */
if (ptr != NULL) {
*(ptr + 5) = 480; /* assign 480 to sixth integer */
printf("Value of the 6th integer is %d",*(ptr + 5));
}
}Output:
Value of the 6th integer is 480
Malloc function can also be used with the character data type as well as complex data types such as structures.
What is Memory? Memory is very much like our brain as it is used to store data and instructions. Computer...
CAD software refers to a type of software program used by engineers and designers to create 2D and 3D...
What is Perl? PERL is a high-level, general-purpose, interpreted, dynamic programming language. Perl...
When people talk about the essentials for the perfect gaming experience, many of them forget to...
IP camera software are applications that can be used for home surveillance, business, and family...
What is a Data Frame? A data frame is a list of vectors which are of equal length. A matrix...