Angus Angus - 7 months ago 60
C Question

Return value of printf() function in C


function will return the number of characters printed. But in the code below
why is it printing 5.

int a=1000;

It prints "1000" once and a space, so altogether we have 2 characters.

It should output "1000 2". But its outputting "1000 5".

Mat Mat

The number of characters output is 5. 1000 is four characters. \n is one character.

printf doesn't return the number of "items" output like the scanf family of functions do for input. It returns the actual character count.