c语言字符常量和字符串常量_C语言中的字符常量

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语言字符常量和字符串常量

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值