Presentation is loading. Please wait.

Presentation is loading. Please wait.

程式語言.

Similar presentations


Presentation on theme: "程式語言."— Presentation transcript:

1 程式語言

2 Introduction C是一種通用的程式語言,它主要用來進行系統程序設計。 C具有高效、靈活、功能豐富、表達力強和移植性好等的特點。
C語言是由UNIX的研製者丹尼斯·里奇(Dennis Ritchie)和肯·湯普遜(Ken Thompson)於1970年研製出的B語言的基礎上發展和完善起來的。

3 About C 1983年,美國國家標準委員會(ANSI)對C語言進行了標準化
1983年,ANSI頒佈了第一個C語言標準草案(83 ANSI C) 1987年,ANSI又頒佈了另一個C語言標準草案(87 ANSI C) 1999年,ANSI頒佈在2000年3月被採用的C99 但由於未得到主流編譯器廠家的支持,直到2004年C99 並未被廣泛使用 增加了若干新特性後 C99 已經逐漸讓C語言和C++分道揚鑣。

4 Course Outline C的面貌 基本資料型態 運算子 判斷及迴圈 複合資料型態 函數 指標

5 Chapter 1 C的面貌

6 C的面貌 第一個C程式 "HELLO" C 程式組成份子 陳述句 註解 引用檔 稱之 main() 的主程式

7 第一個C程式 "HELLO" #include <stdio.h> #include <stdlib.h>
int main(int argc, char *argv[]) { printf("hello!!\n"); printf("C\n"); system("PAUSE"); return 0; } /* hello!! C */

8 C程式的組成份子 C是函數的集合 函數是陳述句的集合 也稱為 程序 或 子程式 且具有可選擇的全域變數 能跨越多重檔案
陳述句必須要用 { } 包括 main() 是第一個被執行的函數

9 C的翻譯過程

10 陳述句和註解 陳述句可以有多種表示方法 以分號來當作陳述句的結尾 陳述句沒有限制一定要單行完成 註解需要使用 /* */包括 或是 //開頭
例如:函數呼叫、數學運算 以分號來當作陳述句的結尾 陳述句沒有限制一定要單行完成 註解需要使用 /* */包括 或是 //開頭 /* 這是註解 */ // 這也是註解

11 引用檔 #include 宣告編譯器在編譯期間需加入指定檔案 大部分用在定義常數和函數引用 引用檔宣告需要在任何程序之前
實際上發生在開始編譯之前 大部分用在定義常數和函數引用 引用檔宣告需要在任何程序之前 標準引用檔( #include <stdio.h> ) 也可以自行設計引用檔 自訂引用檔( #include "mydefs.h" )

12 標準輸出入介面 提供:指令列、檔案、核心輸出入 三個預先定義的輸出入介面: stdin
"standard input" (keyboard) stdout "standard output" (screen) stderr "standard error" (screen) 指令列大部分使用 stdin 或 stdout

13 Keyboard Input #include <stdio.h> #include <stdlib.h>
int main(int argc, char *argv[]) { int n1, n2; float sum; printf("Enter the 1st number:"); scanf("%d", &n1); printf("Enter the 2nd number:"); scanf("%d", &n2); sum = n1 + n2; printf("The Average is %f \n", sum / 2); system("pause"); return 0; }

14 Sample Output Enter the 1st number: 10 Enter the 2nd number: 23 The average is 如果只要兩位小數可以修改如下例: printf ( "The average is %2f\n", sum/2); The average is 16.50

15 總結 C的面貌 程式存在一個或是多個C檔中 程式文件可以用#include引入其他檔案 程式文件擁有一個或多個函數 函數又包含多個陳述句
三個預先定義的輸出入介面

16 附錄 printf("%d\n", i); =fprintf(stdout, "%d\n", i); scanf("%d", i);
=fscanf(stdin, "%d", i); stdin、stdout、stderr 屬於 FILE *


Download ppt "程式語言."

Similar presentations


Ads by Google