C printf and scanf

The printf() function is used to display output and the scanf() function is used to take input from users.

The printf() and scanf() functions are commonly used functions in C Language. These functions are inbuilt library functions in header files of C programming.

printf() Function

In C Programming language, the printf() function is used for output.

printf() function can take any number of arguments. First argument must be enclosed within the double quotes “hello” and every other argument should be separated by comma ( , ) within the double quotes.

Important points about printf():

  • printf() function is defined in stdio.h header file. By using this function, we can print the data or user-defined message on monitor (also called the console).
  • printf() can print a different kind of data format on the output string.
  • To print on a new line on the screen, we use “\n” in printf() statement.

C language is case sensitive programming language. For example, printf() and scanf() in lowercase letters treated are different from Printf() and Scanf(). All characters in printf() and scanf() builtin functions must be in lower case.


printf("format specifier",argument_list);

The format string for output can be %d (integer), %c (character), %s (string), %f (float) %lf (double) and %x (hexadecimal) variable.

Simple Example of printf() Function


int  main()
int num = 450; 
// print number  
printf("Number is %d \n", num);

return 0;

Run : http://ideone.com/bQ3SGW

Tutorials Class - Output Window

Number is 450

scanf() Function

The scanf() function is used to read input data from the console.

The scanf() function is builtin function available in the C library. scanf() function can read character, string, numeric & other data from keyboard in C language.

scanf() reads formatted data from user and assign them in the variables provided the additional arguments. Additional arguments must point to variables that have the same datatype as of user input data format.


scanf("format specifier",argument_list);

Simple Example of scanf() Function


int main()
int x;
printf("enter the number =");
printf("The number is=%d",x);
return 0; 

Run : http://ideone.com/fL7mnO

Tutorials Class - Output Window

enter the number =10
The number is=10

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.