【发布时间】:2018-03-03 17:43:03
【问题描述】:
如何删除此警告?
warning: format '%d' expects argument of type ' int', but argument 2 has type 'int *' [-Wformat=] printf(“%d”,p1->j);
这是代码,除了警告之外一切正常。
void main()
{
struct s1
{
int *j;
};
struct s2
{
int k;
};
struct s1 *p1;
struct s2 *p2;
p1=malloc(sizeof(struct s1));
p2=malloc(sizeof(struct s2));
p2->k=5;
p1->j=&p2->k;
printf("%d",p1->j);
}
【问题讨论】:
-
printf("%d",p1->j);->printf("%d",*(p1->j)); -
是一些学习指针练习的代码吗?因为它没有任何其他意义。
-
你真的应该能够在没有外界帮助的情况下理解这样的警告。仔细阅读该警告。 BTW
malloc可能会失败,你应该测试一下 -
不是编程问题 OP需要一本C书
-
如何测试
mallocs 的结果和free-ing 使用后分配的结构...?
标签: c format-specifiers