Submit Search
Upload
C語言基本資料型別與變數
•
0 likes
•
126 views
吳錫修 (ShyiShiou Wu)
Follow
變數與記憶體, 基本資料型別, 變數宣告與使用, 截短與溢位, &取址運算子, 常值與符號常數
Read less
Read more
Technology
Report
Share
Report
Share
1 of 25
Download now
Download to read offline
Recommended
C語言函式
C語言函式
吳錫修 (ShyiShiou Wu)
Lab 6
Lab 6
alish sha
Lab 9 sem ii_12_13
Lab 9 sem ii_12_13
alish sha
Lab 10 sem ii_12_13
Lab 10 sem ii_12_13
alish sha
C Structure and Union in C
C Structure and Union in C
Bosco Technical Training Society, Don Bosco Technical School (Aff. GGSIP University, New Delhi)
Lecture 6- Intorduction to C Programming
Lecture 6- Intorduction to C Programming
Md. Imran Hossain Showrov
Lecture 9- Control Structures 1
Lecture 9- Control Structures 1
Md. Imran Hossain Showrov
2.overview of c++ ________lecture2
2.overview of c++ ________lecture2
Warui Maina
Recommended
C語言函式
C語言函式
吳錫修 (ShyiShiou Wu)
Lab 6
Lab 6
alish sha
Lab 9 sem ii_12_13
Lab 9 sem ii_12_13
alish sha
Lab 10 sem ii_12_13
Lab 10 sem ii_12_13
alish sha
C Structure and Union in C
C Structure and Union in C
Bosco Technical Training Society, Don Bosco Technical School (Aff. GGSIP University, New Delhi)
Lecture 6- Intorduction to C Programming
Lecture 6- Intorduction to C Programming
Md. Imran Hossain Showrov
Lecture 9- Control Structures 1
Lecture 9- Control Structures 1
Md. Imran Hossain Showrov
2.overview of c++ ________lecture2
2.overview of c++ ________lecture2
Warui Maina
Lecture 18 - Pointers
Lecture 18 - Pointers
Md. Imran Hossain Showrov
Lecture 12 - Recursion
Lecture 12 - Recursion
Md. Imran Hossain Showrov
String Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
Bosco Technical Training Society, Don Bosco Technical School (Aff. GGSIP University, New Delhi)
Function overloading(C++)
Function overloading(C++)
Ritika Sharma
Data structure week 3
Data structure week 3
karmuhtam
C programming structure & pointer
C programming structure & pointer
argusacademy
C programming(part 3)
C programming(part 3)
SURBHI SAROHA
Lecture 8- Data Input and Output
Lecture 8- Data Input and Output
Md. Imran Hossain Showrov
Functions and pointers_unit_4
Functions and pointers_unit_4
Saranya saran
Lecture 10 - Control Structures 2
Lecture 10 - Control Structures 2
Md. Imran Hossain Showrov
Data structure week 2
Data structure week 2
karmuhtam
Programming in C (part 2)
Programming in C (part 2)
SURBHI SAROHA
C,c++ interview q&a
C,c++ interview q&a
Kumaran K
Lecture 7- Operators and Expressions
Lecture 7- Operators and Expressions
Md. Imran Hossain Showrov
Pointer and polymorphism
Pointer and polymorphism
SangeethaSasi1
[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++
Muhammad Hammad Waseem
Pointers in C and Dynamic Memory Allocation
Pointers in C and Dynamic Memory Allocation
Bosco Technical Training Society, Don Bosco Technical School (Aff. GGSIP University, New Delhi)
Intro to c chapter cover 1 4
Intro to c chapter cover 1 4
Hazwan Arif
Oop lec 3(structures)
Oop lec 3(structures)
Asfand Hassan
C programming(Part 1)
C programming(Part 1)
SURBHI SAROHA
1) VariableIn programming, a variable is a container (storage area).pdf
1) VariableIn programming, a variable is a container (storage area).pdf
annamalassociates
vb.net.pdf
vb.net.pdf
VimalSangar1
More Related Content
What's hot
Lecture 18 - Pointers
Lecture 18 - Pointers
Md. Imran Hossain Showrov
Lecture 12 - Recursion
Lecture 12 - Recursion
Md. Imran Hossain Showrov
String Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
Bosco Technical Training Society, Don Bosco Technical School (Aff. GGSIP University, New Delhi)
Function overloading(C++)
Function overloading(C++)
Ritika Sharma
Data structure week 3
Data structure week 3
karmuhtam
C programming structure & pointer
C programming structure & pointer
argusacademy
C programming(part 3)
C programming(part 3)
SURBHI SAROHA
Lecture 8- Data Input and Output
Lecture 8- Data Input and Output
Md. Imran Hossain Showrov
Functions and pointers_unit_4
Functions and pointers_unit_4
Saranya saran
Lecture 10 - Control Structures 2
Lecture 10 - Control Structures 2
Md. Imran Hossain Showrov
Data structure week 2
Data structure week 2
karmuhtam
Programming in C (part 2)
Programming in C (part 2)
SURBHI SAROHA
C,c++ interview q&a
C,c++ interview q&a
Kumaran K
Lecture 7- Operators and Expressions
Lecture 7- Operators and Expressions
Md. Imran Hossain Showrov
Pointer and polymorphism
Pointer and polymorphism
SangeethaSasi1
[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++
Muhammad Hammad Waseem
Pointers in C and Dynamic Memory Allocation
Pointers in C and Dynamic Memory Allocation
Bosco Technical Training Society, Don Bosco Technical School (Aff. GGSIP University, New Delhi)
Intro to c chapter cover 1 4
Intro to c chapter cover 1 4
Hazwan Arif
Oop lec 3(structures)
Oop lec 3(structures)
Asfand Hassan
C programming(Part 1)
C programming(Part 1)
SURBHI SAROHA
What's hot
(20)
Lecture 18 - Pointers
Lecture 18 - Pointers
Lecture 12 - Recursion
Lecture 12 - Recursion
String Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
Function overloading(C++)
Function overloading(C++)
Data structure week 3
Data structure week 3
C programming structure & pointer
C programming structure & pointer
C programming(part 3)
C programming(part 3)
Lecture 8- Data Input and Output
Lecture 8- Data Input and Output
Functions and pointers_unit_4
Functions and pointers_unit_4
Lecture 10 - Control Structures 2
Lecture 10 - Control Structures 2
Data structure week 2
Data structure week 2
Programming in C (part 2)
Programming in C (part 2)
C,c++ interview q&a
C,c++ interview q&a
Lecture 7- Operators and Expressions
Lecture 7- Operators and Expressions
Pointer and polymorphism
Pointer and polymorphism
[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++
Pointers in C and Dynamic Memory Allocation
Pointers in C and Dynamic Memory Allocation
Intro to c chapter cover 1 4
Intro to c chapter cover 1 4
Oop lec 3(structures)
Oop lec 3(structures)
C programming(Part 1)
C programming(Part 1)
Similar to C語言基本資料型別與變數
1) VariableIn programming, a variable is a container (storage area).pdf
1) VariableIn programming, a variable is a container (storage area).pdf
annamalassociates
vb.net.pdf
vb.net.pdf
VimalSangar1
unit 1 (1).pptx
unit 1 (1).pptx
PriyadarshiniS28
C presentation! BATRA COMPUTER CENTRE
C presentation! BATRA COMPUTER CENTRE
jatin batra
Lecture 2 php basics (1)
Lecture 2 php basics (1)
Core Lee
2 variables and data types
2 variables and data types
Tuan Ngo
Perl slid
Perl slid
pacatarpit
Python - variable types
Python - variable types
Learnbay Datascience
C programming tutorial
C programming tutorial
Mohit Saini
PROGRAMMING IN C - Inroduction.pptx
PROGRAMMING IN C - Inroduction.pptx
Nithya K
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
C tokens
C tokens
Megha Sharma
Variable and constants in Vb.NET
Variable and constants in Vb.NET
Jaya Kumari
Data Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# Programming
Sherwin Banaag Sapin
Lecture No 13.ppt
Lecture No 13.ppt
AhmadNaeem59
Datatypes in c
Datatypes in c
CGC Technical campus,Mohali
Data types
Data types
Sachin Satwaskar
12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cpp
sharvivek
qb unit2 solve eem201.pdf
qb unit2 solve eem201.pdf
Yashsharma304389
Unit 2- Module 2.pptx
Unit 2- Module 2.pptx
simranjotsingh2908
Similar to C語言基本資料型別與變數
(20)
1) VariableIn programming, a variable is a container (storage area).pdf
1) VariableIn programming, a variable is a container (storage area).pdf
vb.net.pdf
vb.net.pdf
unit 1 (1).pptx
unit 1 (1).pptx
C presentation! BATRA COMPUTER CENTRE
C presentation! BATRA COMPUTER CENTRE
Lecture 2 php basics (1)
Lecture 2 php basics (1)
2 variables and data types
2 variables and data types
Perl slid
Perl slid
Python - variable types
Python - variable types
C programming tutorial
C programming tutorial
PROGRAMMING IN C - Inroduction.pptx
PROGRAMMING IN C - Inroduction.pptx
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
C tokens
C tokens
Variable and constants in Vb.NET
Variable and constants in Vb.NET
Data Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# Programming
Lecture No 13.ppt
Lecture No 13.ppt
Datatypes in c
Datatypes in c
Data types
Data types
12 computer science_notes_ch01_overview_of_cpp
12 computer science_notes_ch01_overview_of_cpp
qb unit2 solve eem201.pdf
qb unit2 solve eem201.pdf
Unit 2- Module 2.pptx
Unit 2- Module 2.pptx
More from 吳錫修 (ShyiShiou Wu)
mbot2.0教學-陀螺儀與三軸加速計應用.pdf
mbot2.0教學-陀螺儀與三軸加速計應用.pdf
吳錫修 (ShyiShiou Wu)
mbot2.0教學-使用makeblock雲服務.pdf
mbot2.0教學-使用makeblock雲服務.pdf
吳錫修 (ShyiShiou Wu)
mbot2.0教學-局域網路傳輸應用.pdf
mbot2.0教學-局域網路傳輸應用.pdf
吳錫修 (ShyiShiou Wu)
mbot2.0教學-四路顏色感測器應用.pdf
mbot2.0教學-四路顏色感測器應用.pdf
吳錫修 (ShyiShiou Wu)
mbot2.0教學-聲光控制應用.pdf
mbot2.0教學-聲光控制應用.pdf
吳錫修 (ShyiShiou Wu)
mbot2.0教學-光感測器與LED應用.pdf
mbot2.0教學-光感測器與LED應用.pdf
吳錫修 (ShyiShiou Wu)
mbot2.0教學-超音波感測應用.pdf
mbot2.0教學-超音波感測應用.pdf
吳錫修 (ShyiShiou Wu)
mbot2.0教學-移動控制.pdf
mbot2.0教學-移動控制.pdf
吳錫修 (ShyiShiou Wu)
mbot2.0教學-mblock5開發mBot 2.0應用程式.pdf
mbot2.0教學-mblock5開發mBot 2.0應用程式.pdf
吳錫修 (ShyiShiou Wu)
mbot2.0教學-組裝與測試.pdf
mbot2.0教學-組裝與測試.pdf
吳錫修 (ShyiShiou Wu)
Python元組,字典,集合
Python元組,字典,集合
吳錫修 (ShyiShiou Wu)
Python函式
Python函式
吳錫修 (ShyiShiou Wu)
Python串列資料應用
Python串列資料應用
吳錫修 (ShyiShiou Wu)
Python 迴圈作業
Python 迴圈作業
吳錫修 (ShyiShiou Wu)
Python分支作業
Python分支作業
吳錫修 (ShyiShiou Wu)
Python基本資料運算
Python基本資料運算
吳錫修 (ShyiShiou Wu)
建置Python開發環境
建置Python開發環境
吳錫修 (ShyiShiou Wu)
micro:bit加速度感測應用
micro:bit加速度感測應用
吳錫修 (ShyiShiou Wu)
C語言檔案處理
C語言檔案處理
吳錫修 (ShyiShiou Wu)
C語言列舉與聯合
C語言列舉與聯合
吳錫修 (ShyiShiou Wu)
More from 吳錫修 (ShyiShiou Wu)
(20)
mbot2.0教學-陀螺儀與三軸加速計應用.pdf
mbot2.0教學-陀螺儀與三軸加速計應用.pdf
mbot2.0教學-使用makeblock雲服務.pdf
mbot2.0教學-使用makeblock雲服務.pdf
mbot2.0教學-局域網路傳輸應用.pdf
mbot2.0教學-局域網路傳輸應用.pdf
mbot2.0教學-四路顏色感測器應用.pdf
mbot2.0教學-四路顏色感測器應用.pdf
mbot2.0教學-聲光控制應用.pdf
mbot2.0教學-聲光控制應用.pdf
mbot2.0教學-光感測器與LED應用.pdf
mbot2.0教學-光感測器與LED應用.pdf
mbot2.0教學-超音波感測應用.pdf
mbot2.0教學-超音波感測應用.pdf
mbot2.0教學-移動控制.pdf
mbot2.0教學-移動控制.pdf
mbot2.0教學-mblock5開發mBot 2.0應用程式.pdf
mbot2.0教學-mblock5開發mBot 2.0應用程式.pdf
mbot2.0教學-組裝與測試.pdf
mbot2.0教學-組裝與測試.pdf
Python元組,字典,集合
Python元組,字典,集合
Python函式
Python函式
Python串列資料應用
Python串列資料應用
Python 迴圈作業
Python 迴圈作業
Python分支作業
Python分支作業
Python基本資料運算
Python基本資料運算
建置Python開發環境
建置Python開發環境
micro:bit加速度感測應用
micro:bit加速度感測應用
C語言檔案處理
C語言檔案處理
C語言列舉與聯合
C語言列舉與聯合
Recently uploaded
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
soniya singh
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
HostedbyConfluent
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
BookNet Canada
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
Mark Billinghurst
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
ThousandEyes
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
null - The Open Security Community
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
Deakin University
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
Malak Abu Hammad
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
Memoori
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
BookNet Canada
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
XfilesPro
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
Delhi Call girls
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
AndikSusilo4
How to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
naman860154
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Safe Software
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
OnBoard
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
2toLead Limited
Recently uploaded
(20)
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
How to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
C語言基本資料型別與變數
1.
基本資料型別與變數 變數與記憶體 基本資料型別
變數宣告與使用 截短與溢位 &取址運算子 常值與符號常數 Revised on July 25, 2021
2.
Make each day count 變數顧名思義是⼀個隨時可能改變內容的容器名稱,就像家裡的收納 箱可以放入各種不同的東⻄。那麼需要多⼤的收納箱呢? 就要看此收 納箱究竟是要收藏什麼東⻄⽽定
⼤多數程式都會執行資料處理作業,此時程式會請求系統配置記憶體 空間,用來暫存這些運算資料,⽽隨著程式的進行,所暫存的資料內 容可能會變更,因此稱之為變數 (variables) 例如去商店買東⻄時,為了比較價格,我們會記下商品價格,同樣的,程 式是使用變數儲存這些需記住的資料,就可以在需要的時候取出變數值, 例如:執行數學運算和比較等 認識變數 1/4 2
3.
Make each day count 變數儲存在哪裡 當宣告⼀個變數,就會在電腦的記憶體
(memory) 保留⼀個⼤⼩合適的空 間,用來儲存變數資料,換⾔之,變數名稱代表電腦記憶體的⼀個空間 認識變數 2/4 3 10 20 &num1 &num2 變數位址 變數內容 變數名稱
4.
Make each day count 變數資料型別 (data
type) 不同類型資料,所需要的儲存空間⼤⼩也不同,所以在宣告變數時要告知 要用這個變數來儲存什麼樣的資料 例如年齡適合用整數變數,姓名適合用字串變數,身高適合用浮點變數, 性別可以使用字元變數 認識變數 3/4 4
5.
Make each day count 變數的基本操作 讀取變數值:取得目前儲存在變數中的值。讀取變數值,並不會更改變數 目前儲存的值
更新變數值:重新存入另⼀個資料到變數中,原先儲存在變數中的值會被 取代 宣告變數前的準備工作 變數命名,例如 age、name、height和gender等變數名稱 決定變數儲存資料的型態,例如 age 使用整數型別, name 使用字串型別, height 使用浮點數型別,gender 使用字元型別 認識變數 4/4 5
6.
Make each day count 資料型別決定資料容器 (變數)
的格式與容量 字元型別 使用單引號標記字元,例如 'A' 也可使用 ACSII code,例如 65 每⼀個字元型別佔用 8 bits (1 byte) 空間,也可用來儲存 8 位元數值 註:中文字元佔2bytes,所以不能使用字元型別 資料型別 1/3 6 資料型態 說明 位元數 範圍 char 字元 8 -128 ~ 127 unsigned char 無符號字元 8 0 ~ 255
7.
Make each day count 整數型別 整數包含
0、正整數和負整數,例如 123。可使用二進制、八進位、十進位 和十六進位來表示 二進制: 0b 或 0B 開頭的數值,每個位數值為 0~1,例如 0b00100011 八進位:0 開頭的整數值,每個位數的值為 0~7 的整數,例如 0173 十六進位:0x 或 0X 開頭的數值,每個位數值為 0~9和A~F,例如 0x7b 資料型態 說明 位元數 範圍 short int 短整數 16 -32,768 ~ 32,767 unsigned short int 無符號短整數 16 0 ~ 65,535 int 整數 32 -2,147,483,648 ~ 2,147,483,647 unsigned int 無符號整數 32 0 ~ 4,294,967,295 long int ⻑整數 32 -2,147,483,648 ~ 2,147,483,647 unsigned long int 無符號⻑整數 32 0 ~ 4,294,967,295 資料型別 2/3 7
8.
Make each day count 浮點數型別 有⼩數點的數值,例如:123.23
和 4.34 等 也可以使用「e」或「E」符號代表 10 為底指數的科學符號表示 資料型別 3/3 8 資料型態 說明 位元數 範圍 float 單精度浮點數 32 1.18e-38~3.40e+38 double 倍精度浮點數 64 2.23e-308~1.79e+308 long double ⻑倍精度浮點數 80 3.37e-4932~1.18e+4932
9.
Make each day count 變數代表⼀個儲存資料的空間,⽅便程式執行過程中暫存運算資料或 運算結果,因此,其內容可能隨程式執行⽽改變 變數的命名規則
可由英文字⺟或數字或底線字元 (_) 組合⽽成 開頭字元不能使用數字 C 語⾔只辦識變數名稱的前31個字元 區分英文字⺟⼤⼩寫,例如:sum、Sum 和 SUM 是不同的識別字 不能使用 C 語⾔關鍵字 ,例如 int,因為這些字對於編譯器來說具有特殊 意義 使用有意義的文字組合,名稱最好能描述所要儲存的資料,例如 radius、 area;複合字可使用底線字元串接,例如 table_name 宣告變數 1/5 9
10.
Make each day count 駝峰式命名法 (camel
case) 將二個或多個單字連結在⼀起,⽽構成的唯⼀識別字時,單字之間不以 空格、連結號(-)或底線(_)隔開,有兩種格式: ⼩駝峰式命名法 (lower camel case) 第⼀個單字以⼩寫字⺟開始,第二個及之後的單字的⾸字⺟則使用⼤寫,像 是:firstName、somePerson ⼤駝峰式命名法 (upper camel case) 每個單字的⾸字⺟都使用⼤寫字⺟,像是LastName、SomeClass 匈牙利命名法 (Hungarian notation) 在變數名稱前面加上資料型別縮寫的字⾸,例如 intNum、fltAverage、 dTaxes 宣告變數 2/5 10
11.
Make each day count 保留字 (reserved
word) 又稱為關鍵字 (keyword),是C語⾔定義具特 定用途供程式設計使用的識別字 宣告變數 3/5 11
12.
Make each day count 在完成使用變數前的準備工作,即取好變數名稱,和決定資料型態後, 我們就可以撰寫 C
程式碼來宣告變數 資料型態 變數名稱 ; int age; 資料型態 變數名稱1, 變數名稱2 ; int age, salary; 資料型態 變數名稱 = 預設變數值 ; int age = 30; 資料型態 變數名稱1 = 預設變數值, 變數名稱2 ; int age = 30, salary; 宣告變數 4/5 12
13.
Make each day count 變數之記憶體空間 int score; char
grade; 上述程式碼第 1 行宣告⼀個 int 整數變數;變數名稱是 score,可以儲存整 數值 (成績),第 2 行是 char 字元變數;變數名稱是 grade,可以儲存字元 資料 (成績等第) sizeof() 函式可用來查詢變數所佔的記憶體空間 printf("int佔%d byten", sizeof(score)); printf("char佔%d byten", sizeof(grade)); 宣告變數 5/5 13 grade 4 bytes 1 byte
14.
Make each day count 在宣告變數後,就可以使用指定敘述來存取變數值 int score; score
= 20; printf("變數score值是:%n", score); 使用變數 14
15.
Make each day count 指定變數值時,應確認變數宣告的資料型態和所要設定的常數值相符, 例如:帶有⼩數的數值需要指定浮點數型別之變數,不能指定給 int 型別變數,否則⼩數部份會被
truncate (截短) double score; int score2; score = 20.54; score2 = score; 變數值截短 1/2 15
16.
Make each day count 指定超過範圍的值給變數時會造成 overflow
或 underflow char a; a = 128; printf("%dn", a); a = -129; printf("%dn", a); 變數值溢位 2/2 16 負數最小值 正數最大值 0 負數 正數 overflow underflow
17.
Make each day count 當宣告⼀個變數時,會在電腦的記憶體 (memory)
保留⼀個合適的空 間,⽽使用 scanf() 函數讀取輸入資料時,需告知要將資料儲存到那⼀ 個記憶體位址 變數名稱前加上 & 取址運算子表示該變數之記憶體位址 scanf("%d", &score); /* 使用scanf()函數讀取整數 */ &取址運算子 17 &score 儲存到位址為 &score 之記憶體空間 20
18.
Make each day count scanf()函式可⼀次輸入多筆資料,輸入資料時使用空⽩鍵區隔即可 int num1,
num2, num3; scanf("%d %d %d", &num1, &num2, &num3); 輸入多筆資料 18
19.
Make each day count 撰寫程式碼完成以下功能 宣告
int 型別的變數 num,float 型別的變數 value,char 型別的變數 symbol,同時指定 symbol 的初始值 'A',value 的初始值 123.0 讓使用者自行輸入變數 num 的值 在螢幕顯示變數 symbol、value 及 num 的值 在螢幕顯示變數 symbol、value 及 num 的位址 Lab 變數宣告 1/2 19
20.
Make each day count #include <stdio.h> void lab(){ int
num; float value = 123.0; char symbol = 'A'; printf("輸入整數值:"); scanf("%d", &num); printf("變數symbol值為%c,變數value值為%f,變數num值為%dn", symbol, value, num); printf("變數symbol位址為%#X,變數value位址為%#X,變數num位址為%#Xn", &symbol, &value, &num); } Lab 變數宣告 2/2 20
21.
Make each day count 常值 (literal)
或稱常數 (constant) 是指資料本身的值不需要經過宣告, 就直接以電腦能處理的數值或字元資料存在敘述中,例如數字 3、字 串 "three"、字元 '3' 等 C語⾔提供的常值有: 字元常值:單⼀字元資料,例如 'a' 字串常值:連續的字元,頭尾使用雙引號括住,例如 "welcome" 整數常值:整數資料,可以 10 進位、8 進位或 16 進位⽅式 數值預設為10進位 數值後加 l 或 L,表示⻑整數常數,例如 123L 數值後加 u 或 U,表示無號整數常數,例如 123u 常值 1/2 21
22.
Make each day count 8 進位數值常值必須以
0 開頭,例如 0173 16 進位數值常值必須以 0x 或 0X 開頭,例如 0x7b 浮點數常值:帶有⼩數點的數值資料,例如 3.14159 可以使用⼩數點表示法或科學記號 ⼩數點表示法在數值後面加 f 或 F,表示單精確度資料 ⼩數點表示法在在數值後面加 l 或 L,表示倍精確度資料。⼩數點表示 法預設為倍精確度資料 常值 2/2 22
23.
Make each day count 符號常數是指宣告後到程式執行結束,其值不會隨著程式執行⽽改變 C
語⾔提供兩種⽅法建立常數:#define 前置處理指令和 const 關鍵字 使用符號常數會讓程式碼更容易了解及維護 使用 #define 前置處理指令定義符號常數,語法如下: #define 識別字 常數值 #define 前置處理指令與常數的識別字之間⾄少⼀個空⽩字元,常數識別 字與常數值之間也⾄少⼀個空⽩字元 #define PI 3.14159 #define TRUE 1 #define FALSE 0 #define AUTHOR "Wu, ShyiShiou" int main(int argc, char* argv[]) { ... } 符號常數 1/2 23
24.
Make each day count 使用 const
關鍵字定義符號常數,語法如下: const 資料型態 識別字 = 常數值; 因為這是 C 程式敘述,記得在最後加上「;」分號 #include <stdio.h> const double PI = 3.14159; int main(int argc, char* argv[]) { ... } 如果在程式中變更 PI 常數值,編譯時會得到以下錯誤訊息 [Error] assignment of read-only variable 'PI' 符號常數 2/2 24
25.
Make each day count 使用 Dev
C++ 建立 C 程式專案 專案名稱:學號_3 輸入以下程式碼 宣告⼀個符號常數 AUTHOR,內容為個人英文姓名字串 宣告符號常數 PI 為3.14159 宣告 float 型別的變數 radius,宣告 double 型別的變數 perimeter, double 型別的變數 area 讓使用者自行輸入半徑值並存入radius變數 計算圓面積 (𝜋𝑟 ) 並存入 area 變數,計算圓周⻑ (2𝜋𝑟) 並存入 perimeter 變數 套用AUTHOR符號常數,顯示程式作者姓名 顯示圓面積 (到⼩數點第 2 位) 顯示圓周⻑ (到⼩數點第 1 位) 實作練習 25
Download now