#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
指向的字符打印为十进制,这正是它所做的(对于您刚刚释放的内存位置,使得此未定义的行为)。
关于c - 为什么当我打印时,十进制的 *str 显示为 80(ASCII 字母 P)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59457522/