CodeNewbie Community 🌱

Cover image for Input output Statement in C
Alimam Miya
Alimam Miya

Posted on

Input output Statement in C

In this tutorial, we will study the input output statement in c, what is scanf, and printf. so let us start.

What are the input output statements in c?

In the C Language to process an input-output statement, there are two ways or processes. Input means taking the data from the user that will be used in the program and output means the data that will be delivered to the user by displaying it on the monitor.

By using the console we can give input as well as take output. The Console is a black window which is a display monitor and an input device. The console on the execution of the program shows the output of the code.
By the use of Console different-different types of data, input can be given. like

  1. String
  2. Number
  3. Characters
  4. All the primitive types of data ( float, double, long, etc ).

For the Console, there are 2 Standard devices.

  1. Keyboard:- in the C program the keyboard is used to give the input
  2. Monitor:- in the C program the monitor displays the output

C Console Input-output Functions

By using the Console we can perform I/O functions easily by using the built-in functions provided by the c. For Example:-

What is a scanf()?

This is an input function. The standard input-output header file contains the definition of a scanf. This function uses the keyboard to take the input in the program. By using this user can give any primitive types of data input. For Example:-

scanf(β€œ%d”,& variable-name);

In this syntax, the %d is a format specifier which tells the compiler about the input data type. For each type in the C programming language, we have a format specifier that is already defined.

What is a printf()?

printf() is an output function. The standard input-output header file contains the definition of a printf. Printf stands for print formatted. It is used to print formatted output. The user uses the monitor for showing the output. By the use of this function, we can show various primitive types of data to the user. For Example:-

printf(β€œstring/variable”);

In this function, we can print the string directly as well as we can pass any variable whose value we wish to print. The String is written in the double quotes (" "). We can pass both the spring as well as the variable if we wish to. To generate a new line we can use”\n” in the c printf statement.

Format string Meaning
%d Scan or print an integer as a signed decimal number
%f Scan or print a floating-point number
%c To scan or print a character
%s To scan or print a character string. The scanning ends at whitespace

The %d is for the integer. The %f is for the floating numbers. The %c is for the character. The %s is for the string.

Top comments (0)