一.
#include <stdio.h>
#include <stdlib.h>
void trystat(void){
int a=1;
static int b=2; //变量b为具有块作用域的静态变量(存储类别为静态无链接)
printf("a=%d b=%d\n",a++,b++);
}
int main()
{
for(int i=0;i<3;i++){
trystat();
}
return 0;
}
运行截图如下:
总结:即使trystat()函数被调用n次,变量b也只会在trystat()函数第一次被调用时,被初始化一次。
二.
#include <stdio.h>
#include <stdlib.h>
int main()
{
const double RENT=3852.54;
printf("*%f*\n",RENT);
printf("*%e*\n",RENT);
printf("*%.f*\n",RENT);
printf("*%.1f*\n",RENT);
printf("*%3.1f*\n",RENT);
printf("*%8.1f*\n",RENT);
printf("*%-8.1f*\n",RENT);
printf("*%08.1f*\n",RENT);
const double PAY=-3852.54;
printf("*%+8.1f*\n",RENT);
printf("*%+8.1f*\n",PAY);
printf("*%10.1e*\n",RENT);
return 0;
}
运行截图如下:
当变量RENT或PAY的小数点后面为45时,运行截图如下:
当变量RENT或PAY的小数点后面为46时,运行截图如下:
总结:用printf输出浮点数存在四舍五入现象!但是此“四舍五入”有点不太正常。
三.
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
float a;
double b;
long double c;
scanf("%f",&a);
scanf("%lf",&b);
//下面的“行”指的是能运行成功;(在codeblocks中这三种情况下都会有警告)(在devc++中这三种情况下都啥警告没有,但运行却都给你不成功)
scanf("%Lf",&c); //在codeblocks中行,在devc++中不行 ,但是C Primer Plus 6 edition书上说是要这样写
// scanf("%lf",&c); //lf在codeblocks中行,在devc++中也不行,f在codeblocks和devc++中都不行
printf("%f\n",a);
printf("%f\n",b);
printf("%Lf\n",c); //在codeblocks中行,在devc++中不行 ,但是C Primer Plus 6 edition书上说是要这样写
// printf("%lf\n",c); //lf在codeblocks中行,在devc++中不行 ,f在codeblocks和devc++中都不行
int a1;
long b1;
long long c1;
scanf("%d",&a1);
scanf("%ld",&b1);
scanf("%lld",&c1);
printf("%d\n",a1);
printf("%ld\n",b1);
printf("%lld\n",c1);
}