Mangal Pandey Mangal Pandey - 1 year ago 163
C Question

%d expecting int* in c

As per what I know, %d expects an int value. I don't understand why gcc compiler is saying that it expects int* instead.

Here is my code:


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");

printf("\nStudent %d:\n",i+1);
printf("Roll number: ");

And here is the warning:

warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat=]

Answer Source

scanf reads a value into an int, it takes an pointer to the variable to read into.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download