#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