# 變數&運算子 教學長 莊孟寰(JSON / JASON) --- # 變數是啥? ---- ## 顧名思義 ### 就是 變 動的 數 ---- ## 舉個栗子 坐標軸上的X、Y ---- ## 宣告ㄉ語法 變數型態 + 空格 + 變數名稱 + 分號 ---- ## 栗子 ```Cpp= int ans; int 建議變數名稱別用中文; ``` --- # 變數型態 ---- ## 常用的 | 名稱 | 存啥 | -------- | -------- | int | 整數 | long | 整數(建議寫 long long ) | string | 字串 | char | 字元 | bool | ture false ---- ```cpp= int a=123; long long b=123456789123; string c="Hellow"; char d='d'; bool e=true; ``` --- # 運算子 ---- ## 這啥? 簡單來說就是一種數學運算符號 ---- ## 有啥? * 加 + * 減 - * 乘 * * 除 / * mod % * 左移 << * 右移 >> 等等 ---- ## EG ```cpp= a= 1 + 2; //a=3 b= 2 - 1; //b=1 c= 4 * 5; //c=20 d= 9 / 3; //d=3 d= 10 / 3; //d=3 e= 10 % 3; //e=1 f= 1 << 1; //f=2 g= 2 >> 1; //g=1 ``` --- # 小補充 ---- ## 注意變數範圍 ```cpp= int 約介於 -2e9 ~ 2e9 long long 約介於 -9e18 ~ 9e18 ``` ---- ![image](https://hackmd.io/_uploads/SypIdy1nxl.png) ---- * 使用define 把某個 字串 替換成 特定的 字串 ```cpp= #define str string ``` * 使用const 把變數 變成 常數 ```cpp= const int MaxN=100; ``` * 變數名稱要小心不要寫到一些奇特的函數 ~~不然會跟某人一樣一個變數名稱debug了一節課~~ ---- demo --- # 練習題 ---- P68 P266 P339 P6 P215 P216 P297 P378 P385 P386 P47 P48
{"title":"CSDC 變數與運算子","description":"好","contributors":"[{\"id\":\"159a1fd1-6940-4374-8600-52c07b23dee7\",\"add\":1357,\"del\":217,\"latestUpdatedAt\":1768832721904}]"}
    106 views