Tuesday, June 1, 2010

Surprise! C++ version

// Could you explain why this happens:

#include <iostream>

int surprise()
{
    int j = 0;
    if (true) int j = 7;
    return j;
}

int main()
{
    std::cout << "surprise = " << surprise() << std::endl;
    return 0;
}

No comments: