The function of putchar() is to output a character to the terminal. putchar() is an output function with the syntax "putchar(char)". It can write the character specified by the parameter char (an unsigned character) to the standard output stdout. The output of the putchar() function can be a character, a decimal integer between 0 and 127 (including 0 and 127), or a character variable defined with char.
The operating environment of this tutorial: windows7 system, c99 version, Dell G3 computer.
putchar() is a function in C language. Its function is to output a character to the terminal.
The putchar() function is included in the C standard library
The syntax structure is:
int putchar(int char)
The character specified by the parameter char (an unsigned character) can be written to the standard output stdout.
Parameters:
char -- This is the character to be written. The character is passed with its corresponding int value.
Return value
This function returns the written character in the form of unsigned char cast to int, Returns EOF if an error occurs.
Explanation
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 "#".
putchar() function uses
Can the putchar() function only output char type data? With such doubts, I conducted verification on the environment. The verification results are quite interesting, so I would like to share them.
When we define a variable a and assign a value from 0 to 255, there is obviously no problem, such as the code:
#include<stdio.h>void main( ) { int a = 0; //将0值赋给变量a int b = 255; //将255值赋给变量b putchar(a) ; //输出变量a的值 putchar(b) ; //输出变量b的值 putchar('\n') ; }
The result is obviously no problem.
But what if the assigned value is a negative number now? For example, the code:
#include<stdio.h>void main( ) { int a = -4646; //将-4646值赋给变量a int b = -2; //将-2值赋给变量b putchar(a) ; //输出变量a的值 putchar('\n') ; putchar(b) ; //输出变量b的值 putchar('\n') ; }
found that the compilation is normal and the results can be output, but the output results are all empty. I am not sure why?
Another situation is, what happens when the assigned value is greater than 255? The code is as follows:
#include<stdio.h>void main( ) { int a = 592; //将592值赋给变量a int b = 267; //将267值赋给变量b putchar(a) ; //输出变量a的值 putchar('\n') ; putchar(b) ; //输出变量b的值 putchar('\n') ; }
The running result is:
It can be found from the result that the assigned value is truncated into char type data, that is to say, only The lower eight bits of data are taken.
From these examples, the putchar() function does not check the true range of characters to be output.
Conclusion:
When using it, you need to pay attention to whether the range of the output variable is within the range of one character. Only within the range of one character can the correct output be achieved. Otherwise something will definitely go wrong.
Recommended: "c Language 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!

C# is a modern, object-oriented programming language developed by Microsoft and as part of the .NET framework. 1.C# supports object-oriented programming (OOP), including encapsulation, inheritance and polymorphism. 2. Asynchronous programming in C# is implemented through async and await keywords to improve application responsiveness. 3. Use LINQ to process data collections concisely. 4. Common errors include null reference exceptions and index out-of-range exceptions. Debugging skills include using a debugger and exception handling. 5. Performance optimization includes using StringBuilder and avoiding unnecessary packing and unboxing.

Testing strategies for C#.NET applications include unit testing, integration testing, and end-to-end testing. 1. Unit testing ensures that the minimum unit of the code works independently, using the MSTest, NUnit or xUnit framework. 2. Integrated tests verify the functions of multiple units combined, commonly used simulated data and external services. 3. End-to-end testing simulates the user's complete operation process, and Selenium is usually used for automated testing.

Interview with C# senior developer requires mastering core knowledge such as asynchronous programming, LINQ, and internal working principles of .NET frameworks. 1. Asynchronous programming simplifies operations through async and await to improve application responsiveness. 2.LINQ operates data in SQL style and pay attention to performance. 3. The CLR of the NET framework manages memory, and garbage collection needs to be used with caution.

C#.NET interview questions and answers include basic knowledge, core concepts, and advanced usage. 1) Basic knowledge: C# is an object-oriented language developed by Microsoft and is mainly used in the .NET framework. 2) Core concepts: Delegation and events allow dynamic binding methods, and LINQ provides powerful query functions. 3) Advanced usage: Asynchronous programming improves responsiveness, and expression trees are used for dynamic code construction.

C#.NET is a popular choice for building microservices because of its strong ecosystem and rich support. 1) Create RESTfulAPI using ASP.NETCore to process order creation and query. 2) Use gRPC to achieve efficient communication between microservices, define and implement order services. 3) Simplify deployment and management through Docker containerized microservices.

Security best practices for C# and .NET include input verification, output encoding, exception handling, as well as authentication and authorization. 1) Use regular expressions or built-in methods to verify input to prevent malicious data from entering the system. 2) Output encoding to prevent XSS attacks, use the HttpUtility.HtmlEncode method. 3) Exception handling avoids information leakage, records errors but does not return detailed information to the user. 4) Use ASP.NETIdentity and Claims-based authorization to protect applications from unauthorized access.

The meaning of colon (':') in C language: conditional statement: separating conditional expressions and statement block loop statement: separating initialization, conditional and incremental expression macro definition: separating macro name and macro value single line comment: representing the content from colon to end of line as comment array dimension: specify the dimension of the array

A in C language is a post-increase operator, and its operating mechanism includes: first obtaining the value of the variable a. Increase the value of a by 1. Returns the value of a after increasing.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.