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();
}  



Recommended Posts:



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