malloc example in c
Example 1: how to use malloc in c
int* a =(int*)malloc(sizeof(int))
Example 2: how to use malloc in c
ptr = (castType*) malloc(size);
Example 3: malloc in c
int main(int argc, char *argv[])
{
int* string = NULL;
memoireAllouee = malloc(sizeof(int));
if (string == NULL)
{
return;
string[0] = 'H';
string[1] = 'e';
string[2] = 'y';
string[3] = '!';
string[4] = '\0';
printf("%s\n", string);
}
return 0;