11

I am trying to take two variables as input using this code snippet:-

unsigned int i; unsigned long int j; scanf("%u",i); scanf("%lu",j); 

But this give rise to the following warnings :-

warning: format ‘%u’ expects argument of type ‘unsigned int *’, but argument 2 has type ‘unsigned int’ [-Wformat] warning: format ‘%lu’ expects argument of type ‘long unsigned int *’, but argument 2 has type ‘long unsigned int’ [-Wformat] Can anyone explain to me whats happening here?

1 Answer 1

23

You need to add a leading &, as scanf takes pointers to the output parameters. Otherwise, it can not write to them.

scanf("%lu", &i); 
Sign up to request clarification or add additional context in comments.

Comments