The scan function from the stdio.h library enables data to be read from the stdin (usually the keyboard).


scanf() takes a "format string" (enclosed within double quotes) followed by a variable name as its arguments, to be read data from the keyboard.


The scanf() format string requires a format specifier, that indicates the format of the data being passed in to the variable. e.g. %d


takes the format of: scanf("format string", &variable) ;


scanf() requires that an & (address of operator) is used for all variables, apart from strings and pointers



scanf(%d, &myVar) ;

scanf(%s, myString) ;


Note that strings do not require an &, since strings use an array which already comprises of an address pointer

Leave a Reply