2 1 2 include n include iostream h

  • Slides: 22
Download presentation

2. 1. 2 插入標題檔 #include (續) n 插入舊型標題檔 #include <iostream. h> //插入iostream. h標題檔 #include

2. 1. 2 插入標題檔 #include (續) n 插入舊型標題檔 #include <iostream. h> //插入iostream. h標題檔 #include <string. h> //插入string. h標題檔 n 插入新型標題檔 #include <iostream> //插入iostream標題檔 using namespace std; //宣告程式使用新型標題檔

2. 1. 3 main() 函數 n 傳回型態 main(參數) {. return 傳回值; } n 不傳回任何值給系統

2. 1. 3 main() 函數 n 傳回型態 main(參數) {. return 傳回值; } n 不傳回任何值給系統 void main(void) void main() n 傳回整數值給系統 int main(void) int main()

2. 2. 4 宣告符號 #define n #define 對等符號 對等資料 n 範例 #define PI 3.

2. 2. 4 宣告符號 #define n #define 對等符號 對等資料 n 範例 #define PI 3. 14159 void main(void) { float circumference, radius = 10; circumference = 2 * PI * radius; }

2. 2. 5 C++ 保留字 asm auto break bool case catch char class const

2. 2. 5 C++ 保留字 asm auto break bool case catch char class const continue default delete do double else enum explicit extern false float for friend goto if inline int long mutable namespace new operator private proteted public register return short signed sizeof static struct switch template this throw true try typedef typeid typename union unsigned using virtual void volatile while

2. 3. 1 整數資料int 宣告型態 short unsigned short 宣告功能 短整數 無號短整數 有號短整數 數值範圍 -32,

2. 3. 1 整數資料int 宣告型態 short unsigned short 宣告功能 短整數 無號短整數 有號短整數 數值範圍 -32, 768至+32, 767 0至 65, 535 -32, 768至+32, 767 int unsigned int long unsigned long 整數 無號整數 有號整數 長整數 無號長整數 有號長整數 -2, 147, 483, 648至+2147483647 0至 4, 294, 967, 295 -2, 147, 483, 648至+2147483647

2. 3. 5 取得型態大小sizeof n sizeof(資料型態|變數名稱) n 範例 double d. Type; cout << sizeof(int);

2. 3. 5 取得型態大小sizeof n sizeof(資料型態|變數名稱) n 範例 double d. Type; cout << sizeof(int); cout << sizeof(short); cout << sizeof(bool); cout << sizeof(d. Type); 大小 //取得int型態大小 //取得short型態大小 //取得bool型態大小 //取得d. Type變數