C scanf Function
The C scanf function is a standard library function. The Standard Input/Output Library contains functions for formatted data transfer in and out of the C program. The two such functions are as follows:
- printf (print formatted) function
- scanf (scan formatted) function
The data printing and reading functions are defined as standard functions which are part of
the language specification but are not part of the C Language itself. The functions are defined in the system header file stdio.h
The C scanf function is a standard library function to read data from the standard input. This function is the counterpart of the printf function.
The scanf() function reads input from stdin, according to the given format, and stores the data in the other arguments.
The general syntax of the scanf function is:
The format string contains the conversion specifications. The arguments should be pointers to indicate where the input should be stored.
Read an Integer
To read an integer and store it into an integer variable called a number.
The & is the ‘address of‘ operator in the C language. The &number returns the address of the variable number.
Read float Number
In this example, we will use the scanf function to read data into float variable length.