淡淡会遗忘 2022-02-28 16:38 采纳率: 90.9%
浏览 40
已结题

代码打印不出来,报错

struct test
{    
    int Num;
    char* pcName;
    short sDate;
    char cha[2];
    short sBa[4];
}* p;


int main()
{
    p=(struct test*)0x100000;  //假设p的地址是0x100000 
    printf("%p\n",p + 0x1);
    printf("%p\n",(unsigned long)p + 0x1);
    printf("%p\n",(unsigned int*)p + 0x1);
    return 0;
}

[Warning] cast from pointer to integer of different size [-Wpointer-to-int-cast]

想了解下上面的代码哪出问题了,怎么改?

  • 写回答

1条回答 默认 最新

  • yun6853992 2022-02-28 16:49
    关注

    我用vs2019测试了一下,是可以正常运行的:

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 3月1日
  • 已采纳回答 2月28日
  • 创建了问题 2月28日