C Programming

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

#include<stdio.h>
int main()
{
  printf(" %d", printf("%s", "geeksforgeeks"));
  getchar();
}

Irrespective of the string user enters, below program prints 1 . On pressing the run button, the output shown here will be -1, because there is not input. So you must prefer trying this code in Run On IDE

#include<stdio.h>
int main()
{
  char a[50];  
  printf(" %d", scanf("%s", a));
  getchar();
}

Recent Comments

Feedback

For any feedback,email us at feedback@geeksforgeeks.org

Report a Bug

For any report or bug,email us at support@geeksforgeeks.org