C Input Output Functions

C Input Output Functions.

C Statements:

  • There are two types of C Statements.
    1.Input Statements
    2.Output Statements
  • The data given to a program is called ‘Input’ and the result given by the program is called ‘Output’.
  • A function can be imagined as a set of statements aimed to perform a task.
[su_table responsive=”yes” fixed=”yes”]
Input Functions Output Functions
getchar() putchar()
gets() puts()
scanf() printf()



  • getchar() function takes the character and stores it into a variable.
  • Here getchar() function takes the character and stores it into a variable.


  • Using putchar() function we can display a single character as the output on the monitor.
  • Here putchar() function is taking a variable ‘ch’ and it sends the content of that variable to the monitor.

Example: Program to accept and display a single character

void main()
    char  ch;
  • Here, the main() function from where a c program execution starts. After the main() function, we should write { which represents the beginning of the main() function and } which represents the ending of the function.
char ch;

Here, ch is a variable declared as char type. So, it is possible to store a single character in ch.

  • Here,getchar() function waits for the input of a single character. When we enter a character from the keyboard, it reads it and then stores it into the variable ch. Storage is done by the symbol ‘=’ which is called ‘assignment operator’.
  • Here, the putchar() function is displaying the content of ch on the monitor.


  • This function is useful to accept a string from the keyboard and store it into a variable.
  • In this statement, gets() function will accept a string from the keyboard and stores into the variable set.


  • This function displays a string on the monitor.
  • Here, the content of ‘str’ is displayed.

Example: Program to accept and display a name.

void main()
     puts("type your name");

In the above program

char str[20];
  • It represents an array of characters. The name of the array is str. After the array name, we should write [ and ] braces. So, str[] array can accommodate a maximum of 20 characters.


  • This function is useful to accept any type of input. It may be a number, a character or a string.
General Format: scanf(“format string”,variable list);
  • The format string is a string that can represent any of the following format characters shown in the table.
[su_table responsive=”yes” fixed=”yes”]
Format String Meaning
%c A single character
%s A word
%[^\n] A group of words
%i A decimal integer
%d Double integer number.
%f A floating-point number
%lf A long floating-point number
%c Octal number
%x or %X Hexadecimal Number
%e or %E Number in specific form(1.2.e5 means 1.2X10 power 5)


  • The variables in scanf() should be separated by a comma, as shown below.


  • Here,num1 and num2 are variables of integer types. “%d” represents the format string for accepting decimal integer number.


  • This function is useful to display a character, or a string or any numeric value.
General Format:printf(“format string”,variable list);


  • Backslash codes are also called escape sequences.
[su_table responsive=”yes” fixed=”yes”]
Backslash Code
\n To throw the cursor into a new line
\a Beep sound
\t Horizontal tab space
\r Works like entering button in printing
\\ A single \.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: