Home >Backend Development >C#.Net Tutorial >In C language, in what form is char type data stored?
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.
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;
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';
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" 是字符串字面量*/
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!