#include<stdio.h> int D26_1_conver(void) { char ch; int i; float fl; fl = i = ch = 'C'; printf("ch=%c,i=%d,fl=%2.2f\n", ch, i, fl); ch = ch + 1; i = fl + 2 * ch; fl = 2.0 * ch + i; printf("ch=%c,i=%d,fl=%2.2f\n", ch, i, fl); ch = 1107; printf("Now ch=%c\n", ch); ch = 80.89; printf("Now ch = %c\n", ch); return 0; }
#include<stdio.h> void pound(int n);//ANSI函数原型声明 int D26_2_pound(void) { int times = 5; char ch = '!'; //ASCII码是33 float f = 6.0f; pound(times); //int类型的参数 pound(ch); //和pound((int)ch);相同 pound(f); //和pound((int)f);相同 return 0; } void pound(int n) { //ANSI风格函数头 while (n-- > 0) { printf("#"); } printf("\n"); }
在ANSI C以前,C使用的是函数声明,而不是函数原型。函数声明只是指明了函数名以及返回类型,没有指明参数类型,为了向下兼容,C如今容许void pound();//ANSI C以前的函数声明,若是不加int n,那么程序中pound(f)会失败git
https://github.com/ruigege66/CPrimerPlus/blob/master/D26_1_conver.c
https://github.com/ruigege66/CPrimerPlus/blob/master/D26_2_pound.c