# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
# Include <malloc. h>
Int main (void)
{
Char * str1 = NULL;
Char * str2 = NULL;
Char * str3 = NULL;
Char * str4 = NULL;
Char * str5 = NULL;
Str1 = (char *) malloc (2*1024 * sizeof (char ));
If (str1 = NULL)
{
Printf ("malloc error! \ N ");
Return-1;
}
Printf ("malloc 2kb: % P \ n", str1 );
Memset (str1, 'A', 2*1024 * sizeof (char ));
Printf ("mem content: % s \ n", str1 );
Str2 = (char *) realloc (str1, 6*1024 * sizeof (char ));
If (str2 = NULL)
{
Printf ("realloc error! \ N ");
Return-1;
}
Printf ("realloc 6kb: % P \ n", str2 );
Memset (str2, 'B', 6*1024 * sizeof (char ));
Printf ("mem content: % s \ n", str2 );
Str3 = (char *) realloc (str2, 1024*1024 * sizeof (char ));
If (str3 = NULL)
{
Printf ("realloc error! \ N ");
Return-1;
}
Printf ("realloc 1 MB: % P \ n", str3 );
Memset (str3, 'C', 1024*1024 * sizeof (char ));
Printf ("mem content: % s \ n", str3 );
Str4 = (char *) realloc (str3, 3*1024*1024 * sizeof (char ));
If (str4 = NULL)
{
Printf ("realloc error! \ N ");
Return-1;
}
Printf ("realloc 3 MB: % P \ n", str4 );
Memset (str4, 'D', 3*1024*1024 * sizeof (char ));
Printf ("mem content: % s \ n", str4 );
Str5 = (char *) realloc (str4, 10*1024*1024 * sizeof (char ));
If (str5 = NULL)
{
Printf ("realloc error! \ N ");
Return-1;
}
Printf ("realloc 10 MB: % P \ n", str5 );
Memset (str5, 'E', 10*1024*1024 * sizeof (char ));
Printf ("mem content: % s \ n", str5 );
Free (str5 );
Return 0;
}
Use malloc to allocate 2 kb space, and then use realloc to adjust to 6 kb, 1 MB, 3 MB, and 10 MB space, and fill these five memories with "A", "B", "C", "D", and "E" respectively.