Which lines contain errors when using delete operator? (This is not just about compilation errors)

void Test() {
    int a = 0, *p1 = &a, *p2(new int[10]);
    int *p3 = new int;
    delete a; // 1
    delete p1;  // 2
    delete p2;  // 3
    delete p3;  // 4
    delete (int *)a;  // 5
}
Explanation
delete operator accepts only pointers, so line 1 will not compile.
Line 2 is trying to delete the memory for a variable in the stack.
On line 3 delete [] needs to be used.
On line 5, everything is OK - a null pointer is passed to the delete operator.

Слідкуй за CodeGalaxy

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

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