C语言printf函数

#include<stdio.h>
//int float double short char long
int main()
{
    //int printf(const char *format,[argument]);
    //format的格式   %[flags][width][.prec][F|N|h|l]type

    //type的字符用于规定输出数据的类型
    //d、i 接受整数值并将它表示为有符号的十进制整数,i是老式写法
    int a = 10;
    printf("%d\n",a);
    //f  float或double  单精度浮点数或双精度浮点数
    float f = 0.1f;
    double d = 0.1;
    printf("%f\n",f);
    printf("%f\n",d);
    //c char 字符型,可以把输入的数字按照ASCII码相应转换为对应的字符
    char c = 'A';
    char e = 97;
    printf("%c\n",c);
    printf("%c\n",e);
    //s S char 字符串。输出字符串中的字符直至字符串中的空字符(字符串以'\0‘结尾,这个'\0'即空字符)
    char s[] = "abcd"; //不能    char[] s = "abcd";这样写
    printf("%s\n",s);
    //p 输出地址
    int p = 10;
    printf("%p\n",&p);
     // %   输出%本身
    printf("%%\n");

   //  flags 规定输出样式,取值和含义如下:
    int flag = 10;
    int flg = -10;
   //空白   右对齐,左边填充空格
    printf("%d\n",flag);
   // - 减号   左对齐,右边填充空格
    printf("%-d\n",flag);
   // +  加号 在数字前增加符号 + 或 -
    printf("%+d\n",flag);
   // 0 数字零  将输出的前面补上0,直到占满指定列宽为止(不可以搭配使用“-”)
    printf("%06d\n",flag);
   // 空格 输出值为正时加上空格,为负时加上负号
    printf(" % d\n",flag);
    printf(" % d\n",flg);
   //.prec  精度  d、o、i、 u、x 或 X 转换的最少数字显示位数。
    // e 和 f 转换的基数字符后的最少数字显示位数 s 转换中字符串的最大打印字节数目。
    double dou = 1.00;
    printf(" %.8f\n",dou);
   //Argument 如上面的  dou

    //高位寻址  最先定义的变量分配高位地址
    int p1 = 10;
    int p2 = 11;
    printf("p1 %p\n",&p1);
    printf("p2 %p\n",&p2);
    //各种数据类型在系统中所占的位数
    printf("%d\n",sizeof (int));
    printf("%d\n",sizeof(float));
    printf("%d\n",sizeof(double));
    printf("%d\n",sizeof(short));
    printf("%d\n",sizeof(char));
    printf("%d\n",sizeof(long));
    return 0;

    // 转义序列
    //  \a 铃声 (提醒)
    //  \b Backspace
    //  \f 换页
    //  \n  换行
    //   \r 回车
    //   \t 水平制表符
    //   \v  垂直制表符
    //   \'  单引号
    //   \" 双引号
    //   \\ 反斜杠
    //   \? 文本问号
    //   \ooo 在八进制表示法的 ASCII 字符
    //   \ xhh 以十六进制表示法的 ASCII 字符

}
10
0.100000
0.100000
A
a
abcd
0022FEBC
%
10
10
+10
000010
  10
 -10
 1.00000000
p1 0022FEB8
p2 0022FEB4
4
4
8
2
1
4

 

posted @ 2014-01-18 21:35  天之涯0204  阅读(544)  评论(0编辑  收藏  举报