What happens a a result of the following code execution?
class A
{
public:
     void print(const char* buf)
     {
          cout << buf << endl;
     }
};

int main()
{
     ((A*)0)->print("Test");
     return 0;
}
Explanation
Dereferencing of the NULL-pointer - is an Undefined Behavior
ISO/IEC 14882:2003:
1.9/4 Certain other operations are described in this International Standard as undefined (for example, dereferencing the null pointer)
5.2.5/3 If E1 has the type "pointer to class X", then the expression E1->E2 is converted to the equivalent form (*(E1)).E2; ...

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты