C语言中的%0nd,%nd,%-nd

C语言中的%0nd

printf --> formatted print/格式化输出

一、十进制

d -> decimal/十(shí)进制

    int a=1;  
    int b=1234;  
    double c=1.2345678;  
    printf("%2d
",a);  
    printf("%+2d
",a);  //在前面补充‘+’号
    printf("%4d
",a); // 在前面补空格 
    printf("%-4d
",a); // 在后面补空格 
    printf("%2d
",b);  
    printf("%+2d
",b);  
    printf("%4d
",b);   
    printf("%2.2f
",c);  

结果如下:

二、十六进制%x

x -> hexadecimal,其中hexadecimal来自于古希腊,这个词语 is composed of hexa-, derived from the Greek έξ (hex) for six, and -decimal, derived from the Latin for tenth.

三、八进制%o

o -> octal; [1935–40; < Latin oct(ō) or Greek okt(ṓ) eight + -al1]

参考:
1、Print formatted data to stdout

原文地址:https://www.cnblogs.com/xuanyuanchen/p/5855893.html