【发布时间】:2016-08-21 15:05:28
【问题描述】:
据我所知, %d 需要一个 int 值。我不明白为什么 gcc 编译器说它需要 int* 。
这是我的代码:
#include<stdio.h>
#include<stdlib.h>
struct student
{
int rn, m[5];
char nm[25];
};
int main()
{
struct student* s[5];
struct student **q=s;
int i = 0;
printf("Enter data");
for(i=0;i<5;i++)
{
printf("\nStudent %d:\n",i+1);
printf("Roll number: ");
scanf("%d",(s[i])->rn);
printf("\n%d",s[i]->rn);
}
}
这是警告:
warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat=]
scanf("%d",(s[i])->rn);
【问题讨论】:
-
scanf需要一个指针,因此它实际上可以更改 int 的值。 -
另外
s[i]未初始化。
标签: c