Printf And Scanf - C Tutorial

Printf And Scanf

printf() and scanf() functions are inbuilt library functions in C programming language which are available in C library by default. These functions are declared and related macros are defined in "stdio.h" which is a header file in C language.

Output using printf() function

We use printf() function to print/display output on console (monitor).

Syntax of printf() function

printf("format specifiers", variable_list);

printf() function accepts a format string as first parameter. Format string contains string or message we want to print on screen. Optionally, it may contain format specifiers in case we need to print variable value.

Input using scanf() function

scanf() is a versatile function to read input from standard input device (keyboard). It can input any primitive or derived type.

Syntax of scanf() function

scanf("format-specifiers", var1-memory-address, ... );

scanf() accepts a string containing list of format specifiers. Format specifier is a special string starts with % symbol, followed by a character. It directs scanf() or printf() function to input or output a variable value of some type.

For example - %d is a format specifier that tells scanf() to read an integer value. %f is used for float. Likewise there are lot of format specifiers for different types.

We use & (address operator) to get actual memory address of any variable.