Home > Common Problem > What is the function of putchar()

What is the function of putchar()

藏色散人
Release: 2023-02-14 16:17:18
Original
20042 people have browsed it

The function of putchar() is to output a character to the terminal; the syntax structure of putchar is "int putchar(int char)", which means writing the character specified by the parameter char to the standard output stdout; putchar is C Library functions, included in the C standard library.

What is the function of putchar()

The operating environment of this article: Windows 7 system, Dell G3 computer, C11 version.

The syntax structure of putchar() is int putchar(int char). Its function is to write the character specified by the parameter char (an unsigned character) to the standard output stdout. It is a C library function and is included in C Standard library .

The output can be a character, a decimal integer between 0 and 127 (including 0 and 127), or a character variable defined with char .

putchar syntax

(1) Function declaration

int putchar(int char)
Copy after login

(2) Parameter

char--This is the character to be written. The character is passed with its corresponding int value.

(3) Function

Write the character specified by parameter char (an unsigned character) to the standard output stdout. [3]

(4) Description

This function outputs the characters corresponding to the value of the specified expression to the standard output terminal. The expression can be a character type or an integer type, and it can only output one character at a time. For example: "putchar('#')" outputs the character "#".

Return value

This function returns the written character as an unsigned char cast to int, or EOF if an error occurs.

Example

The following example demonstrates the use of the putchar() function.

#include <stdio.h>
int main ()
{
   char ch;
   for(ch = &#39;A&#39; ; ch <= &#39;Z&#39; ; ch++) {
      putchar(ch);
   }
   
   return(0);
}
Copy after login

Let us compile and run the above program, which will produce the following results:

ABCDEFGHIJKLMNOPQRSTUVWXYZ
Copy after login

Recommended: "c Video Tutorial"

The above is the detailed content of What is the function of putchar(). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template