What will be printed out as a result of the following code's execution? Operator delete is a standard one, not redefined.
#include <iostream>
using namespace std;

int main(void) { 
    int a = 1;
    int *pa = &a;
    int &k = *pa;
    delete pa;

    cout << k << "\n";
}
Explanation
In accordance with ISO/IEC 14882:2011 standard (and at least the one preceding it) program behavior is undefined in the case when delete operator (from the standard library) receives a non-null pointer that was created not by a new operator (from the standard library). Undefined behaviour means that a different result may be obtained when executing program on different compilers, with different settings, for every subsequent call, etc. PS. In a general case the program should not allow an undefined behavior.

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

Get it on Google Play