works and does not generate errors.
We are assinging memory address 0x0000 to pt.(I can print the address as you can see above)
Isn't that memory address reserved and currently in use by OS etc. ? I expected crash..
There is nothing wrong syntactically with assigning a pointer improperly. This is partly why using straight pointers can be so dangerous.
Bad pointers will not cause runtime errors unless you attempt to dereference them (IE: access what they point to). It's alright to point to memory address 0 (which is all that above code is doing), just as long as you don't access memory address 0.
1 2 3 4 5 6
int* pt = 0; // okay
int* anotherptr = pt; // also okay -- only points to address 0
int foo = *pt; // CRASH (but no compiler error) -- can't read from address 0
*pt = 5; // CRASH (but no compiler error) -- can't write to address 0
Zero is a special value for pointers, it doesn't represent a real memory location, that just means that they are pointing to nothing
If you try int* pt = 0x1234; you would get an error