Wednesday, 16 March 2016

Returned values of printf() and scanf()

In C, printf() returns the number of characters successfully written on the output and scanf() returns number ofitems 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();
}

0 comments:

Post a Comment