Malloc In C++ Geeksforgeeks Code Example


Example 1: 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] = '\0';   printf("%s\n", string);   free(string); }  /// output : "Hey!"

Example 2: malloc c++

void* malloc(size_t size);

Example 3: how to use malloc in c

ptr = (cast-type*) malloc(byte-size)

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable