筆記網站
筆記網站
# Get Start 前情提要
Program language
- C
- C++
- Java
- JavaScript
- Python
Source-code Editor
- VS code
- dev c++
- Code::Block
- notepad++
Compiler
![]()
# Introduction 介紹
- 雖然他是一個很古老的語言,也相較底層,但到如今還是一個相當熱門的語言。
- 他是很多語言的基礎,學習 C 語言後,在學習其他語言,會更加容易上手。
- C 語言 與 UNIX 密切相關,因為它是為編寫 UNIX 作業系統而開發的。
- C 語言 相較於其他語言來說,較為快速。
# Base 基本概念
Rule
- Left to Right, Up to Down
;at the end of each line of instructionsreturn 0 ;end of program- Use TAB
{}content in structure
Comment
// …single line/* … */multi-line
# Syntax 語法
get start
#include <stdio.h> | |
int main(){ | |
... | |
return 0; | |
} |
引入函式庫
Standard Library Header File 標準函式庫標頭檔
主函式
程式執行的主要內容,任何程式的切入點
備註:學到 function 後會更加清楚
# Variable 變數
# Declare
Data type 變數名稱 = 資料; |

# Data Type
Primitive Data Types :
int, float, char, bool, voidDerived Data Types :
function, array, pointer, referenceAbstract or User-Defined Data Types :
Class, Structure, Union, Enumeration, Typedef defined Datatype
# Primitive Data Type
These data types are built-in or predefined data types and can be used directly by the user to declare variables.
| Data Type | byte | Remark |
|---|---|---|
| Int 整數 | 4 byte | range from ≈ 10^9 |
| Float 單精度浮點數 | 4 byte | |
| Double 雙經度浮點數 | 8 byte | range from -128 to 127 or 0 to 255 |
| Char 字元 | 1 byte | True(1) or False(0) |
| Bool 布林 | 1byte | used for function which does not return a value |
| Void 無 / 空 |

1byte == 8bits
# Identifiers
- Can contain letters, digits and underscores
- Must begin with a letter or an underscore (_)
- case sensitive (myVar and myvar are different variables)
- Cannot contain whitespaces or special characters ( ! # % ……)
- Reserved words cannot be used (like C keywords, such as int)
# Constants
常數
無法被更改的數值
const Data type 變數名稱 = 資料; |

# I/O
# Printf
輸出
將資料輸出,顯示在螢幕上

輸出變數
將變數輸出,顯示在螢幕上


輸出變數於特定格式
將變數輸出成特定格式,顯示在螢幕上

# Escape
\跳脫字元\0空字元 (NULL)\tTAB\n換行\a響鈴 (BEL)\”雙引號\’單引號
# Scanf
輸入
輸入資料,需要利用變數來放入輸入的資料


# Getchar/Putchar
字元輸入 / 輸出
如果輸入了兩個以上的字元,則 getchar 會取得第一個字元,並將第二個字元留在緩衝區中,直到再使用 getchar 或 scanf 取得輸入。

# Operator

# Arithmetic Operators
+加法-減法*乘法/商數除法%餘數除法
# Assignment Operators
=指派+=複合指派

# Relational Operators
>大於>=大於等於<小於<=小於等於==等於!=不等於
# Logical Operators
&&AND 且![]()
||OR 或![]()
!NOT 相反![]()
# Unary Operators
++ / --
- postfix-expression ++
- ++ unary-expression

# Challenge

(B)

(A)

(A)

(B)
# Encoding
# ASCII
American Standard Code for Information Interchange
# Control flow
# Selection Statements
經由判斷條件是 TRUE 或是 FALSE,來選擇要執行哪段程式
- If … else
- Switch case
# Iteration Statements
重複執行單個或多個運算式,在每次執行前會先判斷條件式,若為 FALSE 或是 break,才會中斷。
- While
- Do while
- For loop
# Jump Statements
- Break 中斷
中斷並結束迴圈。 - Continue 繼續
中斷當次迴圈循環,到開頭在執行一次。
# Selection Statements
# If … else
# Switch
# Thinking
請問右邊程式執行後會輸出什麼呢?

# Iteration Statements
# While
# Do while
# For loop
# Nested loop
巢狀是指東西如同鳥巢一樣,一層一層的包下去,而程式中的巢狀迴圈是, while/for 迴圈內包著 while/for 迴圈。

# Midway Challenge


























