C - scanf() function control character

Introduction

Within the control string for the scanf() function, the % character identifies the start of a format specification for an item of data.

f that follows the % indicates that the input should be interpreted as a floating-point value.

The following table lists the basic set of format specifiers you can use for reading data of various types.

Action
Required control string
To read a value of type short
%hd
To read a value of type int
%d
To read a value of type long
%ld
To read a value of type float
%f or %e
To read a value of type double
%lf or %le

in the %ld and %lf format specifiers, l is lowercased.

You must always prefix the name of the variable that's receiving the input value with &.

Related Topic