If abc is the input, then the following program fragment
char x, y, z ;
printf ("% d" , scanf ("%c%c%c" , &x , &y , &z )) ;
results in
Answer: D
Correct answer: printing of 3
scanf returns the number of input items successfully assigned. With the input abc and three %c conversions, all three characters are read and assigned, so it returns 3, and the outer printf prints that.
Note that %c does not skip whitespace as most conversions do, so the three characters read are exactly the next three in the stream. Checking this return value is the correct way to detect a failed or partial scanf, and neglecting it is a common source of bugs.
Please log in or register to report this question.