Returned values of printf() and scanf()

In C, printf() returns the number of characters successfully written on the output and scanf() returns number of items successfully read.

For example, below program prints geeksforgeeks 13

int main()
{
  printf(" %d", printf("%s", "geeksforgeeks"));
  getchar();
}  

Irrespective of the string user enters, below program prints 1.

int main()
{
  char a[50];  
  printf(" %d", scanf("%s", a));
  getchar();
}  





Practice Tags :
Article Tags :
Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.

Recommended Posts:



1.5 Average Difficulty : 1.5/5.0
Based on 77 vote(s)