Crazy puzzles

    After a heated discussion , I had a question: really, how many people who know (or believe that they know) C ++ can answer a question similar to the “simple test” from the article under discussion.


    int test (int x) {
      static const int y = test (x + 1) * 2;
      return x + y;

    int main () {
      std :: cout << test (42) << std :: endl;
      std :: cout << test (0) << std :: endl;

    1. For which version of GCC will this program work?
    2. What will it display?
    3. How to refactor the test () function so that it becomes compatible with the standard (and with GCC 4.2, respectively)?

    Well, a couple of simpler examples (approximately as a problem number two there):
    4. How to describe a function inside a class that does not belong to a class (that is, it is neither a static nor a dynamic class method)?
    5. Why is this feature needed in C ++?

    And finally, the question: is it worth asking such questions at an interview?

    PS Tips write in white over white, as usual ...

    Also popular now: