请告诉*first
在这里打印什么
struct Node{
int info;
struct Node *next;
};
void main()
{
struct Node* first=NULL;
struct Node* second=NULL;
struct Node* third=NULL;
first=(struct Node*) malloc(sizeof(struct Node));
second=(struct Node*) malloc(sizeof(struct Node));
third=(struct Node*) malloc(sizeof(struct Node));
first->info=1;
first->next=second;
printf("*first %d ->\n ",*first); //6487584 ?? what is *first is here should it be same as first->info?
printf("first %d ->\n",first); //13439936
printf("&first %d ->\n",&first); //6487608
printf("&first->info %d ->\n",&first->info); //13439936
printf("&first->next %d ->\n",&first->next); //13439944
}
输出:
最佳答案
所有这些
printf("*first %d ->\n ",*first);
printf("first %d ->\n",first);
printf("&first %d ->\n",&first);
printf("&first->info %d ->\n",&first->info);
printf("&first->next %d ->\n",&first->next);
由于格式说明符%d
(需要int
参数)与提供给printf<的实际参数类型之间不匹配而产生未定义的行为
.
它们不会打印任何有意义的内容。
虽然可以通过使用正确的格式说明符和/或强制转换来挽救打印指针值的尝试,但打印 *first
是不可挽救的。 *first
是一个struct Node
类型的值。 printf
中没有适当的格式说明符来以任何有意义的方式处理此类值。
关于c - 这段代码中*first 打印的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46482803/