“apa gunanya malloc di c” Kode Jawaban

malloc di 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] = '\0';
  printf("%s\n", string);
  free(string);
}

/// output : "Hey!"
Thurger

apa gunanya malloc di c

In C, the library function malloc is used to allocate a block of memory on the heap. The program accesses this block of memory via a pointer that malloc returns. When the memory is no longer needed, the pointer is passed to free which deallocates the memory so that it can be used for other purposes.
Wandering Weevil

Jawaban yang mirip dengan “apa gunanya malloc di c”

Pertanyaan yang mirip dengan “apa gunanya malloc di c”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya