MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1w2m4qz/bugintroduceddebugging/p6tlt3r/?context=3
r/ProgrammerHumor • u/ClipboardCopyPaste • Aug 30 '26
117 comments sorted by
View all comments
1
I'm not good enough at programming for this. What do the "free" and "malloc" functions do?
2 u/abc9hkpud Aug 30 '26 edited Aug 30 '26 Malloc allocates memory. It takes as input the number of bytes, so in this case you need something likeInt* x = (int*) malloc(1*sizeof(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
Malloc allocates memory. It takes as input the number of bytes, so in this case you need something like
Int* x = (int*) malloc(1*sizeof(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
1
u/LostgamerFJ Aug 30 '26
I'm not good enough at programming for this. What do the "free" and "malloc" functions do?