Input output Statement in C
Tags: cprogramming, programming, tutorial, beginners
Published: 2021-02-11 09:20:00

<p>In this tutorial, we will study the <a href="https://usemynotes.com/input-output-statement-in-c/">input output statement in c</a>, what is scanf, and printf. so let us start.</p>
<h2>What are the input output statements in c?</h2>
<p>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.</p><p>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.<br>
By the use of Console different-different types of data, input can be given. like </p>
<ol>
<li>String</li>
<li>Number</li>
<li>Characters</li>
<li>All the primitive types of data ( float, double, long, etc ).</li>
</ol>
<h3>For the Console, there are 2 Standard devices.</h3>
<ol>
<li><strong>Keyboard</strong>:- in the C program the keyboard is used to give the input</li>
<li><strong>Monitor</strong>:- in the C program the monitor displays the output</li>
</ol>
<p><strong>C Console Input-output Functions</strong></p>
<p>By using the Console we can perform I/O functions easily by using the built-in functions provided by the c. For Example:-</p>
<h2>What is a scanf()?</h2>
<p>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:-</p>
<table class="table table-bordered table-striped">
  <tbody>
    <tr>
      <td> <p>scanf(“%d”,& variable-name); </p>
      </td>
    </tr>
  </tbody>
</table>
<p>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.</p>
<h2>What is a printf()?</h2>
<p>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:-</p>
<table class="table table-bordered table-striped">
  <tbody>
    <tr>
      <td> <p> printf(“string/variable”);</p>
        </td>
      </tr>
    </tbody>
  </table>
<p>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.</p>
<table class="table table-bordered table-striped">
  <tbody>
    <tr>
      <th>Format string</th>
      <th>Meaning</th>
    </tr>
    <tr>
      <td>%d</td>
      <td>Scan or print an integer as a signed decimal number</td>
    </tr>
    <tr>
      <td>%f</td>
      <td>Scan or print a floating-point number</td>
    </tr>
    <tr>
      <td>%c</td>
      <td>To scan or print a character</td>
    </tr>
    <tr>
      <td>%s</td>
      <td>To scan or print a character string. The scanning ends at whitespace</td>
    </tr>
  </tbody>
</table>
<p>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.</p>