The article directories

  • Character type (char)
    • 1. Basic introduction
    • 2. Basic cases
    • 3. Character type usage details
    • 4. The nature of character types
    • 5. ASCII code introduction
    • 6. ASCII comparison table

Character type (char)

1. Basic introduction

  • A character type can represent a single character. The character type ischar.char1A string of bytes (which can hold letters or numbers) is called a string in CUse char arrays to represent stringsAn array is not a basic data type, but a construction type

2. Basic cases

  • %c means output as characters
void main(a) {
char c1 = 'A';
char c2 = '0';
char c3 = '\t';
printf("c1=%c c3=%c c2=%c", c1, c3, c2); //%c indicates the output as characters
getchar();
}
Copy the code

3. Character type usage details

  1. Character constants are quoted in single quotes (' '), a single character. Such as:char c1 = 'a'; char c3 = '9';
  2. C also allows the escape character ‘\‘to convert the following character to a special character constant.

    For example,: char c3 = '\n';// ‘\n ‘indicates a newline
  3. In C,charThe essence of aThe integer, at output, isASCIIThe character corresponding to the code.
  4. You can just give it tocharAssign an integer, and then output it according to the correspondingASCIICharacter output [97]
  5. charA type is operable, equivalent to an integer, because it’s all trueUnicodeCode.
  6. Case demonstration:

#include<stdio.h>

void main(a){
	char c1 = 'a';
	char c2 = 'b';
	// When we output as %c, we will install the ASCII table corresponding to 97 characters output
	char c3 = 97;
	printf("c1=%c c2=%c c3=%c", c1, c2, c3);
	getchar();
}
Copy the code

4. The nature of character types

  1. Character type storage to the computer, the need to find the corresponding character code value (integer) storage: character ‘A’ — > code value (97) — > binary (1100001) — > storage () read: binary (1100001) — > code value (97) — > character ‘A’ — > read (display)
  2. The correspondence between characters and code values is determined by the character code table.

5. ASCII code introduction

  1. Inside the computer, all data is represented in binary. Each bit has two states, zero and one, so eight bits can combine 256 states, which is called a byte. A byte can be used to represent a total of 256 different states, and each state corresponds to a symbol, that is, 256 symbols, ranging from 0000000 to 11111111.
  2. ASCII code: last century in the 1960s, the United States developed a set of character codes, the relationship between English characters and binary bits, do uniform rules. This is called ASCII code. ASCII codes specify 127 characters in total, such as 32 for the SPACE “SPACE” (binary 00100000) and 65 for the uppercase letter A (binary 01000001). The 128 symbols (including 32 non-printable control symbols) occupy only the last seven bits of a byte, with the first bit uniformly specified as zero.
  3. Look at a complete ASCII table

6. ASCII comparison table