Home » C programming language

Value returned by scanf function in C language



In this article, we are going to learn about scanf function, what does scanf returned in c programming language?
Submitted by Manju Tomar, on September 20, 2017

scanf() in C language

This is a library function of stdio.h, it is used to read value from the standard input device (keyboard).

The thing that we are going to discuss here is its return type.

Return type of scanf()

scanf() returns total number of inputs. For example, if you are taking 3 inputs through single scanf(), scanf() will return 3.

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: %d\n",result);
    
    return 0;
}

Output

Enter two number: 10 20
Total inputs: 2

In this program, we entered two values 10 and 20. Thus, there are two inputs and the output is "Total inputs: 2".

"This is very basic program written by me (I started learning C programming language few weeks ago). I found this topic very useful to share. If you liked, please leave your comment..."






Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.