Possible Duplicate:
How does Duff’s device work?
int n=5;
int q=(n+3)/4;
switch(n%4)
{
case 0:do{ n++;
case 3:n++;
case 2:n++;
case 1:n++;}while(--q>0);
}
cout<<n;
What will the value of n be?
This is just the code snippet and the answer that is given is 10. Cannot see how?
Final value of
nis 10. Before the switchnis 5, andqis 2. Switch goes to case 1.nis incremented 1 time in first iteration, and 4 more times in second. Finallynhas the value 5+1+4 = 10.