这个小程序,为什么要-'0’
#include<stdio.h>#include "stdafx.h"
int year=0,month=0,day=0;
void getDate(char *num)
{ year=(num[6]-'0')*1000+(num[7]-'0')*100+(num[8]-'0')*10+(num[9]-'0');
month=(num[10]-'0')*10+(num[11]-'0');
day=(num[12]-'0')*10+(num[13]-'0');
}
void main()
{ char num[20];
printf("请输入身份证号: \n");
scanf("%s",num);
getDate(num);
printf("%d年,%d月,%d日",year,month,day);
}
求year时,为什么要-'0'