C - Library functions - Using free()

The free() function is the sister of the malloc() function. As malloc() returns the address of the first byte of the allocated memory, free() accepts, as only parameter, the address of this first byte.

/*
** Made by BadproG
*/

#include	<stdlib.h>
#include	<stdio.h>

int     main()
{
  char	*myString;

  myString = malloc(sizeof(myString));
  if (myString == NULL)
    {
      printf("Can not malloc(), not enough space in the memory!\n");
      exit(1);
    }
  else
    {
      printf("OK memory is allocated!\n");
      free(myString);
    }
  return (0);
}

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Refresh Type the characters you see in this picture. Type the characters you see in the picture; if you can't read them, submit the form and a new image will be generated. Not case sensitive.  Switch to audio verification.