作者wawi2 (@@)
看板C_and_CPP
標題[問題] ternary ? operator
時間Wed Dec 12 00:22:18 2018
因為工作升遷需求 需要考證照
在準備的時候遇到兩個很怪的問題 而且compile也不過
想請問怎麼解釋下面的code?
(工作上要是有人這樣寫我會想砍人 但這是考試...you know...)
1.
int main() {
int a = 3;
cout<<s(a)<<endl;
return 0;
}
int s(int n)
{
if(n == 0) return 1;
return s(n?1)*n;
}
這邊要怎麼解釋 s(n?1)
2. complex class本身有real part (re)跟imaginary part (im)
但這邊的 this?>re + t.re是啥意思 沒看過?>這東西
complex complex::operator+ (complex &t){
complex temp;
temp.re = this?>re + t.re;
temp.im = this?>im + t.im;
return temp;
}
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 108.5.129.170
※ 文章網址: https://webptt.com/m.aspx?n=bbs/C_and_CPP/M.1544545340.A.B01.html
※ 編輯: wawi2 (108.5.129.170), 12/12/2018 00:30:21
1F:→ wawi2: 對了 因為這畢竟是人家背出來的考題 或許有筆誤。。。。 12/12 00:39
2F:→ stucode: 我覺得這應該不是程式碼,是填空題吧? 12/12 00:59
3F:→ stucode: 問號處都用-(減號)填入看起來很合理。 12/12 00:59
4F:推 mmmmei: 我投筆誤一票 12/12 01:00
5F:推 ckc1ark: 我猜是用到non-ascii的 dash-like symbol encoding出問題 12/12 01:11
6F:→ wawi2: 謝謝大家 把?全換成-就都合理了 12/12 01:30
7F:→ wawi2: 看來明顯是原作者把word轉存成pdf時 把全形-轉成? 12/12 01:37
8F:推 b0920075: 笑了 12/12 05:06
9F:→ MOONRAKER: 噗 你要不要修改標題加上 (被騙了) 12/12 17:42