字元包含了:
'
跟反斜線\
跟其他特殊符號一樣,在前面加反斜線
整數和字元間轉換會遵守ASCII編碼
用迴圈印出a~z (ascii code 97~122)
(X) cout << “abcdefghijklmnopqrstuvwxyz”
既然字元是透過數字表達
字元與字元間、字元與數字間也可以運算、比大小
例如:‘Q’ - ‘P’, ‘p’ + 1, ‘q’ - 2
給你 1000 根棍子,老闆叫你
第 1 根棍子跟第 1000 根棍子接起來
第 2 根棍子跟第 999 根棍子接起來
…
第 500 根棍子跟第 501 根棍子接起來
因為要趕著出貨的關係,你已經等不及想知道這些棍子接起來長度
於是你決定寫一個程式算好答案
簡單:
宣告1000個int
cin 1000次
用for迴圈相加
cout 500次
趕快打開你心愛的 IDE 開始敲鍵盤
偉大的Code就此誕生
Here are the specific C 2018 rules about that:
This means that in each instance an object is used, the C standard does not impose any requirements on which value is used for it. It is not required to be the same as a previous use. The program may behave as if it does not hold any fixed value. When it is used multiple times, the program may act as if it has a different value each time. For example, the C standard would allow printf("%d %d %d\n", a, a, a); to print “34 -10200773 2147483204”.
A way this can happen is that, while attempting to compile the code int a; printf("%d %d %d\n", a, a, a);, the compiler has nowhere to get a from, because it has never been given any fixed value. So, instead of generating useless instructions to move data from uninitialized memory to where the arguments are passed, the compiler generates nothing. Then printf gets called, and the registers or stack locations where the arguments are passed contain whatever data they had from earlier. And that may well be three different values, which printf prints. So it looks to an observer of the output as if a had three different values in printf("%d %d %d\n", a, a, a);.
(In addition, using the value of an uninitialized object with automatic storage duration that has not had its address taken is explicitly undefined behavior, because 6.3.2.1 2, about converting an object to its value, says “If the lvalue designates an object of automatic storage duration that could have been declared with the register storage class (never had its address taken), and that object is uninitialized (not declared with an initializer and no assignment to it has been performed prior to use), the behavior is undefined.” So, when there is an object meeting these criteria, using its value can break the program completely; it might not only have different values at different times, but the program might abort, go down a branch different from what you expected, not call printf when there is a printf in the source code, and so on.)
e.g. 輸入 n 個數字,把他存到一個陣列裡面
一個字元一個字元的說話很累耶
把多個字元串在一起
0 | 1 | 2 | 3 | 4 |
---|---|---|---|---|
'c' | 'p' | 's' | 'd' | '\0' |
會輸出甚麼?
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
---|---|---|---|---|---|---|---|---|---|---|
'H' | 'e' | 'l' | 'l' | 'o' | 'W' | 'o' | 'r' | 'l' | 'd' | '\0' |
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
---|---|---|---|---|---|---|---|---|---|---|
'H' | 'e' | 'l' | 'l' | 'o' | '\0' | 'o' | 'r' | 'l' | 'd' | '\0' |
你可以這樣:
0 | 1 | 2 | 3 | |
---|---|---|---|---|
0 | 'a' | 'b' | 'c' | '\0' |
1 | 'd' | 'e' | 'f' | '\0' |
2 | 'g' | 'h' | 'i' | '\0' |
a011: 00494 - Kindergarten Counting Game
從輸入值集合 到可能的輸出值集合 的函數 記作 是 與 的關係,滿足如下條件:
- 是完全的
- 是多對一的
是完全的
對輸入值集合 裡的任何元素
輸出值集合 裡存在
是多對一的
允許
不允許
國中數學課本裡的例子:
函數:販賣機
輸入:錢 + 想買的飲料的編號
輸出:飲料 + 找零 or 找零(錢不夠)
一般的函數大概會長這樣:
要使用定義好的函數,我們只要看清楚函數宣告的第一行:
相同名稱的函數但傳入的參數不同
任何程式語言的學習都沒有一步登天的方式,一步步來慢慢學
小murmured:
偶覺得神奇把大家想的很神奇
也太難ㄌ吧🥴
水獺