Each time I submit a program on hackerrank the following error occurs.
solution.c: In function ‘main’:
solution.c:22:14: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat=]
printf("%d", &sum);
It would be very helpful if someone could tell me what this means?
I assume that you have declared sum
as an int
. So the correct call to printf
is :
printf("%d", sum);
as %d
specifier means that you are going to print an int
, but you are passing the int
's address, which is a pointer to int
, or int *
.
NOTE : Do not confuse printf
with scanf
, as the second does require a pointer. So, for reading variable sum
, you would use :
scanf("%d", &sum);
but for printing, the correct way is without &
, as written above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With