In this article, we will be focusing on the scanf() function in C in detail.

Working of the scanf() function in C

Be it any programming language, we always need user input, in order to make it work with a dynamic set of values.

This is where the scanf() function in C comes into picture.

The scanf() function enables the programmer to accept formatted inputs to the application or production code. Moreover, by using this function, the users can provide dynamic input values to the application.

Having understood the working of scanf() function, let us now focus on the structure of the same.


Syntax of scanf() function

Let us have a look at the below syntax:

**scanf**``(``"%format-specifier"``, &variable)

  • format_specifier: It decides the type of value to be taken as input from the standard input device. Example: “%d” for integer, “%c” for character values, etc.
  • variable: The value taken as input from the user gets stored at the location pointed by the variable.

The scanf() function accepts the value of the specified type through the help of the format specifiers and stores the value at the location pointed by the variable passed as a parameter to it.

Let us now implement the scanf() function through the below examples.

#c programming #c

The scanf() function in C - Accepting userinput in C
1.15 GEEK