将算术运算应用于char类型的值

#include stdio.hint main(void){char first = A;char second = B;char last = Z;

编程学习网为您整理以下代码实例,主要实现:将算术运算应用于char类型的值,希望可以帮到各位朋友。

#include <stdio.h>

int main(voID)
{
  char first = 'A';
  char second = 'B';
  char last = 'Z';

  char number = 40;

  char ex1 = first + 2;                     // Add 2 to 'A'
  char ex2 = second - 1;                    // Subtract 1 from 'B'
  char ex3 = last + 2;                      // Add 2 to 'Z'

  printf("Character values      %-5c%-5c%-5c\n", ex1, ex2, ex3);
  printf("Numerical equivalents %-5d%-5d%-5d\n", ex1, ex2, ex3);
  printf("The number %d is the code for the character %c\n", number, number);
  return 0;
}
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐