//以十进制、八进制和十六进制输出100,加入#会显示前缀
#include<stdio.h>
int main()
{
int x = 100;
printf("dec = %d; octal = %o;hex = %x
",x,x,x);
printf("dec = %d; octal = %#o;hex = %#x
",x,x,x);
return 0;
}
//整数溢出
#include<stdio.h>
int main()
{
int i = 2147483647;
unsigned int j = 4294967295;
printf("%d %d %d
",i,i+1,i+2);
printf("%u %u %u
",j,j+1,j+2);
return 0;
}
//printf()更多的属性
#include<stdio.h>
int main()
{
unsigned int un = 3000000000;
short end = 200;
long big = 65537;
const __int64 verybig = 12345678908642;//long long 我的编译器不支持
printf("un = %u and not %d
",un,un);
printf("end = %hd and %d
",end,end);
printf("big = %ld and %hd
",big,big);
printf("verybig= %lld and not %ld
",verybig,verybig);
printf("%d
",sizeof(__int64));
return 0;
}
//显示一个字符的编码值
#include<stdio.h>
int main()
{
char ch;
printf("Please enter a character.
");
scanf("%c",&ch);
printf("The code for %c is %d.
",ch,ch);
return 0;
}
//可移植的整数类型名
#include<stdio.h>
#include<inttypes.h>
int main(void)
{
int16_t me16;
me16 = 4593;
printf("Frist,assume int16_t is short:");
printf("me16 = %hd
",me16);
printf("Next,let's not make any assumptions.
" );
printf("Instead,use a "macro" from inttypes.h: ");
printf("me16 = %" PRID16"
",me16);
return 0;
}
//%f 与%e的转换
#include<stdio.h>
int main()
{
float about = 32000.0;
double abet = 2.14e9;
long double dip = 5.32e-5;
printf("%f can be written %e
",about,about);
printf("%f can be written %e
",abet,abet);
printf("%f can be written %e
",dip,dip);
return 0;
}
//float 在系统假设最大值为3.4E38时,下面代码会发生上溢
#include<stdio.h>
int main()
{
float toobig = 3.4E38 * 100.0f;
printf("%e
",toobig);
}
//结果不等于1,因为计算机缺乏足够的进行正确运算所需的十进制位数。
//数字2.0e20为2后面加上20个零,如果对它加一改变的将是第21位,而float只有6,7位有效位数
#include<stdio.h>
int main()
{
float a,b;
b = 2.0e20 +1.0;
a = b - 2.0e20;
printf("%f
",a);
return 0;
}
/*输出类型的大小*/
#include<stdio.h>
int main()
{
printf("Type int has a size of %lu bytes.
",sizeof(int));
printf("Type char has a size of %u bytes.
",sizeof(char));
printf("Type long has a size of %u bytes.
",sizeof(long));
printf("Type double has a size of %u bytes.
",
sizeof(double));
return 0;
}
//将浮点值变为整数,c简单地丢弃小数部分(截尾),而不进行四舍五入
#include<stdio.h>
int main()
{
int cost = 3.5415926;
printf("%d
",cost);
}
/*
printf中参数不足和类型不匹配所造成的结果随平台的不同而不同。
%d显示float值不会进行转换,而是显示垃圾值,其他类型也一样
*/
#include<stdio.h>
int main()
{
int f = 4;
int g = 5;
float h = 5.0f;
printf("%d
",f,g);
printf("%d %d
",f);
printf("%d %f
",h,g);
return 0;
}
//转义字符
#include<stdio.h>
int main()
{
float salary ;
printf("aEnter your desired monthly salary:");
printf(" $_______");
scanf("%f",&salary);
printf("
$%.2f a month is $%.2f a year.",salary,
salary*12.0);
printf("
Gee!
");
return 0;
}