Which lines case errors?
int main() {
    int n = 10, m = 100;
    int *p;
    int* const p1 = new int(n);
    int const* p2 = &n;

    *p = n;   //1
    p = &n;   //2
    *p1 = m;  //3
    p1 = p;   //4
    *p2 = m;  //5
    p2 = p1;  //6
}
Explanation
1) since the p pointer is not initialized, it can point to any memory area. That's why assigning the value will cause an execution error (undefined behavior).
3) all good here - you can change the value of the pointer-constant
4) it is impossible to change the address of the pointer-constant
5) p2 - pointer to a constant value, and the value of the constant cannot be changed
6) all good here - a non-constant pointer was assigned to a pointer-constant

Следи за CodeGalaxy

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

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