Prashant | Sun, 14 Jun, 2020 | 132
In this tutorial we are gonna learn that what value is returned by printf and scanf funcrtions ?
printf is a library function of stdio.h, it is used to display messages as well as values on the standard output device (monitor).
printf returns an integer value, which is the total number of printed characters.
For example: if you are printing "Hello" using printf, printf will return 5.
Consider the program:
#include <stdio.h>
int main()
{
int result;
result = printf("Hello\n");
printf("Total printed characters are: %d\n",result);
return 0;
}
Output
Hello Total printed characters are: 6
In first statement "Hello\n" there are 6 characters, "\n" is a single character to print new line, it is called new line character. Thus, total number of printed characters are: 6.
scanf is a library function of stdio.h, it is used to take input from the standard input device (keyboard).
scanf returns an integer value, which is the total number of inputs.
For example: if you are reading two values from scanf, it will return 2.
Consider the program:
#include <stdio.h>
int main()
{
int a,b;
int result;
printf("Enter two number: ");
result=scanf("%d%d",&a,&b);
printf("Total inputs are: %d\n",result);
return 0;
}
Output
Enter two number: 10 20 Total inputs are: 2.
1. Introduction And Getting Started With C
3. Why We Should Use C Language
4. Applications Of C Programming
5. Basic Rules For Writting C Program
8. Tokens In C
9. Difference Between Int Main And Void Main
11. Variables In C
13. Difference Between Local And Global Variable
14. Difference Bwtween Auto / Extern / Static Variable
15. Constant In C
16. How To Access Global Variable Using Extern Keyword In C
17. Exit And Return Staterment In C
18. Print Float Value Upto N Decimals In C Programming
19. How To Print Multiline Message Using Single Printf In C Programming ?
20. What Value Returned By Scanf Function In C Language ?
21. What Value Is Returned By Printf And Scanf In C