How to output characters using putchar in C language?

In the C language, the putchar function can be used to output characters. It is a standard library function that allows you to output a single character to the standard output device, usually the console.

Here is an example code demonstrating how to use the putchar function to output characters.

#include <stdio.h>

int main() {
   char c = 'A';  // 定义一个字符变量c,赋值为字符'A'
   
   putchar(c);    // 使用putchar函数输出字符c
   
   return 0;
}

In the example above, we first define a character variable c, assign it the value of the character ‘A’. Then, we use the putchar function to output the character c to the standard output device.

After running the program, the character ‘A’ will be displayed on the console.

bannerAds