The putchar() function is used to write a single character to the standard output device. The usage steps are as follows: include the <stdio.h> header file. Define an integer variable representing the character to be written. Use the putchar() function to print characters to the console.
putchar() function is used in C language
putchar() function is used in C language Function that writes a single character to the standard output device (usually the console). The syntax is as follows:
<code class="c">int putchar(int character);</code>
Among them:
character
: The character to be written, expressed as an integer. Usage Example
The following example demonstrates how to use the putchar() function to print characters to the console:
<code class="c">#include <stdio.h> int main() { char character = 'A'; putchar(character); return 0; }</code>
In this example:
<stdio.h>
header file, which contains the declaration of the putchar() function. Running this program will output the letter 'A' to the console.
Other examples
The following are more examples showing the use of the putchar() function:
Print newline characters :
<code class="c">putchar('\n');</code>
Print multiple characters:
<code class="c">char string[] = "Hello, world!"; for (int i = 0; i < strlen(string); i++) { putchar(string[i]); }</code>
Print without printing newlines:
<code class="c">putchar('A'); putchar('B');</code>
Note:
The above is the detailed content of Examples of usage of putchar in C language. For more information, please follow other related articles on the PHP Chinese website!