I have the following C program, and I don't understand the return value from scanf.
#include <stdio.h>
int main()
{
int p,n1,n2;
p=scanf("%d %d",&n1, &n2);
printf("%d", p);
return 0;
}
p is assigned the return value from scanf.
When I provide values for n1 and n2, the value of p is always 2. I don't understand why the value is always 2 regardless of what numbers I provide for n1 and n2.
scanf returns the number of values read, which in your case is 2.
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