Who said interviews were just about testing knowledge? In some cases, it can be a bit of a learning experience for everyone involved. Case in point, I was asked about what kind of compiler optimization may be made from the following code:
int CountOccurences(LinkedNode const * const head, int const dataToCount, int occurences) { if (head == nullptr) { return occurences; } if (head->data == dataToCount) { ++occurences; } return CountOccurences(head->link, dataToCount, occurences); }
My initial reaction was that maybe the compiler would attempt to do something to our const vars on the stack, considering they never change in the function. Turns out, there is something more going on here.