C語言printf()函數的格式化字串

來源:互聯網
上載者:User

標籤:strcpy   pre   fun   getch   對齊   \n   nbsp   連結   AMM   

原文連結:
https://www.runoob.com/cprogramming/c-function-printf.html

#include<stdio.h>#include<string.h>int main(void){    charc,s[20],*p;    inta=1234,*i;    floatf=3.141592653589;    doublex=0.12345678987654321;    p="Howdoyoudo";    strcpy(s,"Hello,Comrade");    *i=12;    c=‘\x41‘;    printf("a=%d\n",a); /*結果輸出十進位整數a=1234*/    printf("a=%6d\n",a); /*結果輸出6位十進位數a=1234*/    printf("a=%06d\n",a); /*結果輸出6位十進位數a=001234*/    printf("a=%2d\n",a); /*a超過2位,按實際值輸出a=1234*/    printf("*i=%4d\n",*i); /*輸出4位十進位整數*i=12*/    printf("*i=%-4d\n",*i); /*輸出靠左對齊4位十進位整數*i=12*/    printf("i=%p\n",i); /*輸出地址i=06E4*/    printf("f=%f\n",f); /*輸出浮點數f=3.141593*/    printf("f=%6.4f\n",f); /*輸出6位其中小數點後4位的浮點數    f=3.1416*/    printf("x=%lf\n",x); /*輸出長浮點數x=0.123457*/    printf("x=%18.16lf\n",x); /*輸出18位其中小數點後16位的長浮點數x=0.1234567898765432*/    printf("c=%c\n",c); /*輸出字元c=A*/    printf("c=%x\n",c); /*輸出字元的ASCII碼值c=41*/    printf("s[]=%s\n",s); /*輸出數組字串s[]=Hello,Comrade*/    printf("s[]=%6.9s\n",s); /*輸出最多9個字元的字串s[]=Hello,Co*/    printf("s=%p\n",s); /*輸出數組字串首字元地址s=FFBE*/    printf("*p=%s\n",p); /*輸出指標字串p=Howdoyoudo*/    printf("p=%p\n",p); /*輸出指標的值p=0194*/    getch();    return 0;}

C語言printf()函數的格式化字串

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.