#include<stdio.h>
typedef struct telephone
{
char *name;
int number;
} TELEPHONE;
int main()
{
//TELEPHONE index;
TELEPHONE *ptr_myindex;
ptr_myindex = (TELEPHONE*)malloc(sizeof(TELEPHONE));
//ptr_myindex = &index;
ptr_myindex->name = "Jane Doe";
ptr_myindex->number = 12345;
printf("Name: %s\n", ptr_myindex->name);
printf("Telephone number: %d\n", ptr_myindex->number);
free(ptr_myindex);
return 0;
}
当我编译它时,它输出的结果与我不动态分配指向结构的指针时的结果相同,而是使用我的代码中已被注释掉的部分。为什么会这样?