printf returns the number of characters it prints.
Examples:
If you write an expression like:
x = printf("%s", "Muttley is awesome!"); or
y = printf("%d", 1111);
then, what does printf return to x and y?
x = 19 and y = 4.
scanf returns the number of items it scans. However it stops scanning as soon as you give wrong input.
Examples:
p = scanf("%d%d%d", &y, &z, &w);
r = scanf("%d%d", &y, &z);
If all inputs are correct in the expression for p then,
p = 3. Similarly, r = 2.
Lets say you give wrong third input(may be you enter a character instead of int) in the expression for p, immediately scanf stops and returns the value 2 to p. If the first input is wrong then scanf will return 0 to p.
So we can say that scanf returns the number of items scanned before the first wrong input entered.
(Reminds me of geometric distribution)
No comments:
Post a Comment