Print decimal value of a char

后端 未结 5 979
春和景丽
春和景丽 2021-01-27 10:34

Program to print decimal value of a char:

#include

int main(void){

  char ch = \'AB\';
  printf(\"ch is %d\\n\",ch);

}

Why i

5条回答
  •  醉梦人生
    2021-01-27 11:12

    Iharob is right. 'AB' being a multi character turns out to be not predictable. If you intend to keep the two characters 'AB', I'd recommend declaring this constant as a string char ab[] = "AB";. The print for a string could be printf("ch is %d\n", ab[0]);, to have 65 as output.

提交回复
热议问题