MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1w2m4qz/bugintroduceddebugging/p6tlt3r/?context=3
r/ProgrammerHumor • u/ClipboardCopyPaste • 2d ago
120 comments sorted by
View all comments
2
I'm not good enough at programming for this. What do the "free" and "malloc" functions do?
2 u/abc9hkpud 2d ago edited 2d ago Malloc allocates memory. It takes as input the number of bytes, so in this case you need something like Int* x = (int) malloc(1sizeof(int)) For an int array of length 1. Free is used to free the pointer. After free, you shouldn't access the memory (or return it for someone else to use) Modern C++ uses new and delete instead. Malloc and free are used in C
Malloc allocates memory. It takes as input the number of bytes, so in this case you need something like
Int* x = (int) malloc(1sizeof(int))
For an int array of length 1. Free is used to free the pointer.
After free, you shouldn't access the memory (or return it for someone else to use)
Modern C++ uses new and delete instead. Malloc and free are used in C
2
u/LostgamerFJ 2d ago
I'm not good enough at programming for this. What do the "free" and "malloc" functions do?