C語言學習分享(typedef、變數))

來源:互聯網
上載者:User

標籤:c語言 (typedef、變數)

宏定義

#define MAX 5

#define SUM (10 +5)

#define kSum(a, b) (a + b)   // Sum(a, b)中間不能加空格

printf("kSum is %d\n", kSum(10, 5)); //調用 

int a = 5;

#if MAX == 5

   printf("max is 0\n");

#elif MAX > a   此處a的值為0  未進行編譯時間a未進行賦值預設為0,

   printf("max > %d\n",a); //編譯運行時a進行了賦值,輸出時a的值為5

#else 

   printf("max < 0");

#endif

 

#undef PI   //取消宏定義

 

650) this.width=650;" width="491" height="313" src="/e/u261/themes/default/images/spacer.gif" alt="說明: MAC OS:private:var:folders:nj:rbckmbsn66vbjcrh2bnx43140000gn:T:com.evernote.Evernote:WebKitDnD.ClGBnL:螢幕快照-2015-07-17-上午9.31.28.png" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" />

 

字元數組的輸入輸出 %s 用法

 char name[20];       //注意name 是一個指標常量

scanf(“%s”,name);  //不加&符號

printf(“%s\n”name);

注意:當用指標接收字串時,注意要給指標申請空間

錯誤: char *name;

        scanf(“%s”,name);

錯因:*name未進行初始化,為野指標

正確:char *name;                                                //malloc函數需引入stdlib.h函數

         name = (char *)mallco(sizeof(char) * 20);     //malloc後面跟申請地址空間的大小

         scanf(“%s”,name);

         printf(”name is %s\n”,name);

         free(name);          //申請的地址空間需手動回收即free函數


本文出自 “平凡” 部落格,請務必保留此出處http://10538803.blog.51cto.com/10528803/1676890

C語言學習分享(typedef、變數))

聯繫我們

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