Home  >  Article  >  What are character constants

What are character constants

不言
不言Original
2019-02-23 15:04:2573206browse

What are character constants

The so-called character constant is a character enclosed in English single quotes. When using character constants, you should pay attention to:

1. Uppercase and lowercase characters within single quotes represent different character constants. For example, ‘Y’ and ‘y’ are two different character constants.

2. Character constants can only be enclosed in English single quotes, not double quotes. For example "Y" is not a character constant, but a string.

3. If there is a space character within single quotes, it is also a character constant.

4. Single quotes can only contain 1 character, and the writing of 'xyz' is wrong. But if there are more than 1 character, the previous ones except the last one will automatically become invalid. Of course, this should be avoided in programming.

5. The value of a character constant is its value in the ASCII encoding table. It is an integer from 0 to 127. Therefore, character constants can be operated as integer data. For example:

The value of the expression ‘Y’ 32 is 121, which is the value of ‘y’.

The value of expression ‘7’ ‘6’ is 109. By looking up the table, we can find that it happens to be the value of ‘m’. It should be noted that '7' and 7 are different. As a character constant, the integer constant value represented is 55, which is the integer constant 7.

The characters enclosed in single quotes include 26 uppercase and lowercase English characters, 10 numeric characters, as well as whitespace characters (space characters, tab characters, newline characters), punctuation and special symbols (on the keyboard A total of 30), they are also called the basic character set of C language

The above is the detailed content of What are character constants. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:What language is python?Next article:What language is python?