#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char *str;
/* Initial memory allocation */
str = (char *) malloc(15);
strcpy(str, "tutorialspoint");
printf("String = %s, Address = %u\n", str, str);
/* Reallocating memory */
str = (char *) realloc(str, 25);
strcat(str, ".com");
printf("String = %s, Address = %u\n", str, str);
/* Deallocate allocated memory */
free(str);
printf("\n%d",*str);
return(0);
}
您的最后一次打印表示将指向的字符打印str
为十进制,这正是它所做的(对于您刚刚释放的内存位置,使这种未定义的行为)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句