#include
int main()
{
const int a = 12;
int *p;
p = &a;
*p = 70;
}
Will it work?
Here the type of pointer p
is int*
, which is being assigned the value of type const int*
(&a
=> address of a const int
variable).
Implicit cast eliminates the constness, though gcc throws a warning (please note this largely depends on the implementation).
Since the pointer is not declared as a const
, value can be changed using such pointer.
if the pointer would be declared as const int* p = &a
, you won't be able to do *p = 70
.