c語言中%s和%d的區別

來源:互聯網
上載者:User

標籤:解釋   輸出   nbsp   s函數   數值   creat   color   blog   turn   

 1 /************************************************************************* 2     > File Name: ptr_both.c 3     > Author: Mr.Yang 4     > Purpose:思考指標指向字串和指向整型的區別  5     > Created Time: 2017年06月03日 星期六 17時37分17秒 6  ************************************************************************/ 7  8 #include <stdio.h> 9 #include <stdlib.h>10 #include <string.h>11 12 int main(void)13 {14         /*指標指向字串示範*/15         char *s1 = "hello";16         char *p1 = strchr(s1,‘l‘);//返回首次出現該字串的地址17         printf("%s\n",p1);//%s它要求參數是一個指標!!!   puts函數也要求它的參數是一個指標,而不能是數值!!!18 19         /*指標指向整型示範*/20         int s2[] = {1,2,3,4};21         int *p2 = s2;22         printf("%d\n",*p2);//%d它要求參數是一個值!!!23 24         return 0;25 }

這也就解釋了為什麼printf同要輸出值,字串和整型需要不同型別參數!!!

 

怎麼從c語言的核心理解這兩個區別,也就是怎麼從字串、整形的儲存原理來理解???

c語言中%s和%d的區別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.