What does the following example do?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++

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/29 23:14:37
What does the following example do?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++

What does the following example do?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++
What does the following example do?
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);
}
}
//The C++ Programming Language (Third Edition) CH6 - 15

What does the following example do?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开始拷贝数据到to.
拷贝数量是 ( ( ( count + 7 ) % 8 ) - 1 ) * 8 + ( count % 8 ) 个元素.
第一次从count%8开始,依次执行 case count%8-1,case count%8-2 ..到
case 1,
然后循环n-1次,执行 do {} 中间的代码.