2015 10 28基礎知識

2021-07-06 08:39:15 字數 2626 閱讀 8969

函式:

函式作用---模組化,**重用,使用方便(printf)

函式定義(函式設計)

儲存型別 資料型別 函式名(引數列表){函式體}

void show_picture(char *path)

{顯示;

}函式引數

形式引數--函式

實際引數-函式被呼叫的時候傳入的引數(初始化形式引數)

引數傳遞(傳值,位址)

main函式傳遞引數

int main(int argc,char **argv);

int 返回值

int argc---程式執行時候傳入引數個數(包括程式本身)

char **argv--程式執行時候傳入引數列表

函式返回值(gcc---函式必須自己宣告,gcc宣告把所有函式的返回值設為int)

(多檔案程式設計)mainpram.cmath.c

gcc -o mainprammainpram.c math.c

函式呼叫-中斷(壓棧)

函式遞迴-函式自己呼叫自己(必須有判斷返回)

函式指標

庫函式,字串庫函式,時間庫函式

字串庫函式:

比較 strcmp strcmp(「hello」,「hello」)==0

拷貝 strcpy char name[32];strcpy(name,「had」);

字串長度計算(不包含\0)strlenstrlen(name);——字串「a」==『a』『\0』

字串查詢子串 strstr——「google」「oo」strstr(「google」,「oo」)如果找到就返回oo所在的位置,如果沒找到就返回null

字串拼接 strcatplayer/users/geek-ios107/desktop/46.mp4

char path[128]=「/users/geek-ios107/desktop/46.mp4」

strcat(path,「/」);—》」users/geek-ios107/desktop/「

strcat(path,「代號47.mp4」);—>/users/gec-ios107/desktop/代號47.mp4

man 函式名/命令-----函式使用說明

時間庫函式(隨機數)

獲取當前時間

#include

time_t time(time_t  *tloc);

把時間轉換字串輸出

char  *ctime(consttime_t *clock);

把秒時間轉換為時間結構

struct tm*gmtime(const time_t *clock);世界時間

int tm_sec;     /* seconds (0 - 60) */

int tm_min;     /* minutes (0 - 59) */

int tm_hour;    /* hours (0 - 23) */

int tm_mday;    /* day of month (1 - 31) */

int tm_mon;     /* month of year (0 - 11) */

int tm_year;    /* year - 1900 */

int tm_wday;    /* day of week (sunday = 0) */

int tm_yday;    /* day of year (0 - 365) */

int tm_isdst;   /* is summer time in effect? */

char *tm_zone;  /* abbreviation of timezone name */

long tm_gmtoff; /* offset from utc in seconds */

獲取隨機數

#include

long random(void);

//設定隨機數因子

void srandom(unsigned seed);

獲取微秒時間

int gettimeofday(struct timeval,*restrict tp,void *restrict tzp);

#include

int main(void)

for(j=i; j>0; j--)

for(j=0; j<=i; j++)

printf("\n");

}return0;}

#include "test3.h"

int main(void)

if(month >= 3)

}printf("%d\n", allday);

return0;}

#include "math.h"

int add(int a, int b)

doublesub(doublea, doubleb)

//函式遞迴---函式自己呼叫自己

//0--i的累加

int fun(int i)

//菲

//1 1 2 3 5 8 13 21 34  ---i

int fdat(int i)

#include

#include

#include

#include

int main(void)

C 基礎知識整理 基礎知識(2) 類

類,是物件導向語言的基礎。類的三大特性 封裝 繼承 多型。最基本的特性就是封裝性。程式設計師用程式描述世界,將世界的所有事物都看成物件,怎麼描述這個物件?那就是類了。也就是用類來封裝物件。用書上的話說,類是具有相同屬性和行為的物件的抽象。寶馬汽車 別克汽車 五菱之光汽車.基本具有相同的屬性和行為,所...

C 基礎知識整理 基礎知識(2) 類

類,是物件導向語言的基礎。類的三大特性 封裝 繼承 多型。最基本的特性就是封裝性。程式設計師用程式描述世界,將世界的所有事物都看成物件,怎麼描述這個物件?那就是類了。也就是用類來封裝物件。用書上的話說,類是具有相同屬性和行為的物件的抽象。寶馬汽車 別克汽車 五菱之光汽車.基本具有相同的屬性和行為,所...

電腦的基礎知識 電腦的基礎知識

電腦的組成部分與其作用 一 軟體系統 軟體系統的組成分別是 作業系統 應用軟體等。其應用軟體是指特定領域開發 並為特定目的服務的一類軟體。而作業系統是位於底層硬碟與使用者之間溝通的橋梁。使用者可以通過作業系統的使用者頁面,輸入命令,實現使用者需求。二 硬體系統 硬體系統是指構成計算機的物理裝置,即由...