作者ric2k1 (Ric)
看板EE_DSnP
標題[情報] 期末考示範考題 (三)
時間Mon Jan 14 00:18:41 2008
(OK... 最後一題)
How many compilation error(s) is(are) there in the following code?
For the assignments on lines 11-13, if they can be compiled, please describe
how the assignments work. If they cannot be compiled, please explain why.
============================================================
1 #include <string>
2
3 using std::string;
4
5 int main()
6 {
7 char a[6] = "12345";
8 char *b = "12345";
9 string c = "12345";
10
11 a = "Hello";
12 b = "World";
13 c = "Peace";
14
15 return 0;
16 }
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.121.135.175
1F:→ ric2k1:這題難易度是: 中等偏難 (觀念要清楚) 01/14 00:19
2F:→ ric2k1:不過其實也沒那麼難, 對吧? 01/14 00:19
3F:推 louis123321:請問...老師允許我這種英文不好的人帶電子字典嘛?? 01/14 00:37
4F:→ ric2k1:看不懂題目的可以舉手問助教或是我... 不要客氣. 01/14 00:39
5F:推 ShooterYang:為甚麼可以把"World"assign給b呢 他不是pointer嗎 01/14 18:11
6F:→ ShooterYang:Pointer不是應該要存一個"位置"? 01/14 18:13
7F:推 ShooterYang:ㄜ....我來亂的 忽然發現這是一道問題 01/14 18:19
8F:→ keyboardle:其實"World"可以assign喔...錯的是另一個... 01/15 18:16