#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)会失败
https://github.com/ruigege66/CPrimerPlus/blob/master/D26_1_conver.c
https://github.com/ruigege66/CPrimerPlus/blob/master/D26_2_pound.c
原文:https://www.cnblogs.com/ruigege0000/p/13752558.html