Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • \$\begingroup\$ The int i=*(int*)0; returns a NullReferenceException for me. \$\endgroup\$ Commented Dec 30, 2011 at 7:43
  • \$\begingroup\$ You can try to access a negative location, like *(int*)-1=0 and get an access violation. \$\endgroup\$ Commented Dec 30, 2011 at 7:46
  • \$\begingroup\$ The particular exception is just what the clr wraps it in, and is insignificant. The os itself actually gives the seg fault in all these cases. \$\endgroup\$ Commented Jan 20, 2012 at 17:41
  • \$\begingroup\$ The reason why *(int*)0=0 throws an exception is likely due to optimization. Specifically, to avoid the cost of checking for null, the optimizer may remove null checks, but when a segfault occurs it may rethrow it as a proper NullReferenceException. \$\endgroup\$ Commented Sep 15, 2018 at 20:55