Home > Backend Development > C#.Net Tutorial > In C language, in what form is char type data stored?

In C language, in what form is char type data stored?

青灯夜游
Release: 2020-10-30 15:26:45
Original
8886 people have browsed it

In C language, char type data is stored in the form of "ASCII code". In C language, putting a character constant into a character variable does not actually put the character itself into the memory unit, but puts the ASCII code corresponding to the character into the storage unit.

In C language, in what form is char type data stored?

Tutorial recommendation: "c language tutorial video"

C language character type (char) introduction

Character type (char) is used to store characters, such as English letters or punctuation. Strictly speaking, char is actually an integer type, because the char type actually stores integers, not characters. Computers use specific integer encodings to represent specific characters. The encoding commonly used in the United States is ASCII (American Standard Code for Information Interchange). For example: ASCII uses 65 to represent the capital letter A, so storing the letter A actually stores the integer 65. Note: Many IBM mainframes use another encoding - EBCDIC (Extended Binary-Coded Decimal Interchange Code); computers in different countries may use completely different encodings.

Declare character variables

Character variables are declared in the same way as other types of variables:

char good; 
char better, best;
Copy after login

The above code declares three Character variables: good, better, and best.

Character constants and initialization

We can use the following statement to initialize character variables:

char ch = 'A';
Copy after login

This statement initializes the value of ch to A Encoded value. In this statement, 'A' is a character constant. In C language, characters are enclosed in single quotes to form character constants. Let's look at another example:

char fail; /* 声明一个字符型变量*/ 
fail = 'F'; /* 正确*/ 
fail = "F"; /* 错!"F" 是字符串字面量*/
Copy after login

In C language, char type data is stored in the form of "ASCII code" in memory.

In C language, putting a character constant into a character variable does not actually put the character itself into the memory unit, but puts the ASCII code corresponding to the character into the storage unit.

For more programming-related knowledge, please visit: Programming Teaching! !

The above is the detailed content of In C language, in what form is char type data stored?. 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