How are character constants represented in the C language?

Character constants in the C language can be represented by enclosing them in single quotes (‘), and can only contain a single character. For example:

char c = 'A';

Special characters, such as backslashes, can be represented using escape sequences in character constants.

char tab = '\t';  // 表示制表符
char newline = '\n';  // 表示换行符
char backslash = '\\';  // 表示反斜杠字符

It is also possible to use hexadecimal to represent character constants, for example:

char hex = '\x41';  // 表示字符'A'

It is important to note that character constants can only contain one character and cannot contain multiple characters. If you need to represent multiple characters, you can use string constants.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds