Skip to content

Instantly share code, notes, and snippets.

@selfboot
Created July 16, 2016 05:49
Show Gist options
  • Select an option

  • Save selfboot/573b1da0fbe0e7c6a568bd9530456766 to your computer and use it in GitHub Desktop.

Select an option

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…
#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