C中的字符算术
字符算术用于对C语言中的字符执行诸如加法和减法之类的算术运算。它用于操纵字符串。当字符用于算术运算时,它将自动将它们转换为整数值,即字符的ASCII值。
这是C语言中的字符算术示例,
示例
#include <stdio.h>
int main(){
char s = 'm';
char t = 'z' - 'y';
printf("%d\n", s);
printf("%c\n", s);
printf("%d\n", (s+1));
printf("%c\n", (s+1));
printf("%d\n", (s-1));
printf("%c\n", (s-1));
printf("%d\n", t);
// printf("%c", t);
return 0;
}输出结果
这是输出-
109 m 110 n 108 l 1