#include<stdio.h>
#include<malloc.h>
#include<string.h>
void foo( char ** ptr)
{
*ptr = malloc(0); // allocate some memory**
strcpy( *ptr, "Hello World");
}
int main()
{
char *ptr = 0;
// call function with a pointer to pointer
foo( &ptr );
printf("%s\n", ptr);
// free up the memory
free(ptr);
return 0;
}
и он также работает
#include<stdio.h>
#include<malloc.h>
#include<string.h>
void foo( char ** ptr)
{
*ptr = malloc(11); // allocate some memory
strcpy( *ptr, "Hello World");
}
int main()
{
char *ptr = 0;
// call function with a pointer to pointer
foo( &ptr );
printf("%s\n", ptr);
// free up the memory
free(ptr);
return 0;
}
изменить malloc на любое число ... оно всегда запущено. Как это возможно ????
Hello World имеет 12 символов, так что можно запустить в 0,12,8, любое число.