Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

malloc in c

#include <stdlib.h>

void *malloc(size_t size);

void exemple(void)
{
  char *string;
  
  string = malloc(sizeof(char) * 5);
  if (string == NULL)
    return;
  string[0] = 'H';
  string[1] = 'e';
  string[2] = 'y';
  string[3] = '!';
  string[4] = '';
  printf("%s
", string);
  free(string);
}

/// output : "Hey!"
 
PREVIOUS NEXT
Tagged: #malloc
ADD COMMENT
Topic
Name
1+2 =