Returned values of printf() and scanf()

1.6

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

GATE CS Corner    Company Wise Coding Practice

Recommended Posts:



1.6 Average Difficulty : 1.6/5.0
Based on 69 vote(s)










Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.