Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
C dynamic memory allocation
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Overview of functions== The C dynamic memory allocation functions are defined in <code>stdlib.h</code> header (<code>cstdlib</code> header in C++).<ref name="c99" /> {| class="wikitable" |- ! Function ! Description |- | {{anchor|malloc}}{{cpp|malloc}} | allocates the specified number of bytes |- | {{anchor|aligned_alloc}}{{cpp|aligned_alloc}} | allocates the specified number of bytes at the specified alignment |- | {{anchor|realloc}}{{cpp|realloc}} | increases or decreases the size of the specified block of memory, moving it if necessary |- | {{anchor|calloc}}{{cpp|calloc}} | allocates the specified number of bytes and initializes them to zero |- | {{anchor|free}}{{cpp|free}} | releases the specified block of memory back to the system |} ===Differences between <code>malloc()</code> and <code>calloc()</code>=== * <code>malloc()</code> takes a single argument (the amount of memory to allocate in bytes), while <code>calloc()</code> takes two arguments — the number of elements and the size of each element. * <code>malloc()</code> only allocates memory, while <code>calloc()</code> allocates and sets the bytes in the allocated region to zero.<ref>{{man|3|calloc|Linux}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)