Created: 2022-06-20
Tags: #fleeting
void pointer of mallocfree() worksLibraries Needed
`#include <stdlib.h>
Purpose of Malloc:
malloc()
void pointer pointing to the first byte of the allocated memory.void pointer of mallocMalloc doesn't have an idea of what it is pointing to nor the data type it's gonna store it to. Therefore it's important to assign a data type by typecasting it. We can write (int *) in front of malloc()
person *myperson = (person *) malloc(sizeof(person));
// person here is name of the struct
sizeof values in each data type of C
malloc(sizeof(int))
Basically sizeof(int) is saying I have 1 int. Since I want three integers, give me three pieces of int -> 3 * sizeof(int). (1)