c语言字符常量和字符串常量
Any character (a single character) that is enclosed within the single quotes (like, 'A') is called character constants in C programming language.
用单引号引起来的任何字符(单个字符)(例如'A' ) 在C编程语言中称为字符常量 。
Character constants contain:
字符常量包含:
Any uppercase alphabet
任何大写字母
Any lowercase alphabet
任何小写字母
A space
空间
A digit
一个数字
Any special character
任何特殊字符
字符常量声明 (Character constant declaration)
A character constant is declared by using const keyword.
使用const关键字声明字符常量 。
Syntax:
句法:
const char constant_name = 'value';
Example:
例:
#include <stdio.h>
int main(void)
{
const char1 = 'A'; //uppercase alphabet
const char2 = 'X'; //uppercase alphabet
const char3 = 'a'; //lowercase alphabet
const char4 = 'x'; //lowercase alphabet
const char5 = '5'; //a digit
const char6 = '#'; //a special character
const char7 = ' '; //a space
//print values
printf("char1 = %c\n", char1);
printf("char2 = %c\n", char2);
printf("char3 = %c\n", char3);
printf("char4 = %c\n", char4);
printf("char5 = %c\n", char5);
printf("char6 = %c\n", char5);
printf("char7 = %c\n", char7);
return 0;
}
Output
输出量
char1 = A
char2 = X
char3 = a
char4 = x
char5 = 5
char6 = 5
char7 =
翻译自: https://www.includehelp.com/c/character-constant.aspx
c语言字符常量和字符串常量