【學習筆記】【C語言】檔案的包含,學習筆記c語言

來源:互聯網
上載者:User

【學習筆記】【C語言】檔案的包含,學習筆記c語言

一、基本概念

#include,它可以將一個檔案的全部內容拷貝另一個檔案中。

二、一般形式

1.第1種形式#include <檔案名稱>
直接到C語言庫函數標頭檔所在的目錄中尋找檔案
 
2.第2種形式 #include "檔案名稱"
系統會先在來源程式目前的目錄下尋找,若找不到,再到作業系統的path路徑中尋找,最後才到C語言庫函數標頭檔所在目錄中尋找

三、使用注意

#include指令允許嵌套包含,比如a.h包含b.h,b.h包含c.h,但是不允許遞迴包含,比如 a.h 包含 b.h,b.h 包含 a.h。

四、代碼

1.

.h檔案

1 #ifndef LISI_H2 #define LISI_H3 4 int sum(int a, int b);5 6 7 #endif

.c檔案

int sum(int a, int b){    return a + b;}

2.

.h檔案

1 #ifndef WANGWU_H2 #define WANGWU_H3 int minus(int a, int b);4 #endif

.c檔案

 1 /* 2  1.<>表示系統內建的檔案,""表示自訂的檔案 3  2.不允許迴圈包含,比如a.h包含b.h,b.h又包含a.h 4  */ 5  6 #include "lisi.h" 7 #include "wangwu.h" 8  9 #include <stdio.h>10 11 int main()12 {13     int c = sum(10, 19);14     15     printf("c is %d\n", c);16     17     return 0;18 }

 

 

聯繫我們

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