c - 这段代码中*first 打印的是什么?

标签 c pointers

请告诉*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

    }

输出:

enter image description here

最佳答案

所有这些

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/

相关文章:

C 程序 : A array containts items ID's, B 数组包含已售出的商品 查找包含未售出商品的 C 数组

c - 循环无法达到极限

c++ - 使用 char 指针加载文件

c - HashTable 如何将重复的单词只打印一次?

c - 是否可以访问 "recursive mode"中的指针?

objective-c - Objective-C 中有两个星号 ** 是什么意思?

c - 在 C 中将非常大的数字存储在整数中

c - Windows 7 驱动程序 - 仅运行一次然后需要重新启动

c - sqlite3_exec的使用

c - 在 C 中查找指针数组的索引