putchar() function in C

The putchar(int char) method in C is used to write a character, of unsigned char type, to stdout. This character is passed as the parameter to this method.

Syntax:

int putchar(int char)

Parameters: This method accepts a mandatory parameter char which is the character to be written to stdout.

Return Value: This function returns the character written on the stdout as an unsigned char. It also returns EOF when some error occurs.

Below examples illustrate the use of putchar() method:



Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C program to demonstrate putchar() method
  
#include <stdio.h>
  
int main()
{
  
    // Get the character to be written
    char ch = 'G';
  
    // Write the Character to stdout
    putchar(ch);
  
    return (0);
}

chevron_right


Output:

G

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C program to demonstrate putchar() method
  
#include <stdio.h>
  
int main()
{
  
    // Get the character to be written
    char ch = '1';
  
    // Write the Character to stdout
    for (ch = '1'; ch <= '9'; ch++)
        putchar(ch);
  
    return (0);
}

chevron_right


Output:

123456789

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


2


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.