Created
July 16, 2016 05:49
-
-
Save selfboot/573b1da0fbe0e7c6a568bd9530456766 to your computer and use it in GitHub Desktop.
The function malloc is used to allocate a certain amount of memory during the execution of a program. The malloc function will request a block of memory from the heap. If the request is granted, the operating system will reserve the requested amount of memory. When the amount of memory is not needed anymore, you must return it to the operating s…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdio.h> | |
| #include <cstdlib> | |
| int main() | |
| { | |
| int *ptr_one; | |
| ptr_one = (int *)malloc(sizeof(int)); | |
| if (ptr_one == 0) | |
| { | |
| printf("ERROR: Out of memory\n"); | |
| return 1; | |
| } | |
| *ptr_one = 25; | |
| printf("%d\n", *ptr_one); | |
| free(ptr_one); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment