C ++ is const pointer to literal value?

I know that lvalues ​​can be converted to const reference. I am curious if I can get a pointer to these lvalues.

If i write

const int* p = &3; //ERROR: lvalue required as unary operand '&'

I get this error. Nonetheless,

const int* p = &((const int&)3);

it compiles. In this case, the result * p is guaranteed to be 3?

+4
source share
1 answer

int(3) . p . , , , p . p ( ) undefined.

+8

Source: https://habr.com/ru/post/1684569/


All Articles