What happens if you compile and execute this code?
class A {};

void Destroy(A *&ptr) {
    delete ptr;
    ptr = 0;

int main() {
    A *a = new A();
In Destroy(), a reference to the pointer is passed, then after the first call of this function, the pointer a will become zero. During the second call of Destroy(), a null pointer will be passed to delete. By standard, the delete operator must correctly process the null pointer, so the program will exit successfully. Also, according to the standard, the main function may not accept arguments and may not contain a return statement.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Зареєструйся Зараз
або Підпишись на майбутні тести