Angus Angus - 1 year ago 120
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
Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download