今天面试面试官让读下面这段代码,然后说出代码作用,看了10分钟后被面试官打断,真没看出这代码到底是做什么的,取得面试官同意后拍照,自己在电脑上跑了跑,没看出这到底是要干什么.
void send(int* to, int* from, int count)
{
int n = (count+7)/8;
switch(count%8) {
case 0: do{ *to++ = *from++;
case 7: *to++ = *from++;
case 6: *to++ = *from++;
case 5: *to++ = *from++;
case 4: *to++ = *from++;
case 3: *to++ = *from++;
case 2: *to++ = *from++;
case 1: *to++ = *from++;
} while(--n>0);
}
}
其实真正的结构是这样的:
void send(int* to, int* from, int count)
{
int n = (count+7)/8;
switch(count%8) {
case 0:
do
{
*to++ = *from++;
case 7: *to++ = *from++;
case 6: *to++ = *from++;
case 5: *to++ = *from++;
case 4: *to++ = *from++;
case 3: *to++ = *from++;
case 2: *to++ = *from++;
case 1: *to++ = *from++;
} while(--n>0);
}
}
慕丝7291255