Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Segmentation fault
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Null pointer dereference === In C and C-like languages, [[null pointer]]s are used to mean "pointer to no object" and as an error indicator, and [[dereferencing]] a null pointer (a read or write through a null pointer) is a very common program error. The C standard does not say that the null pointer is the same as the pointer to [[memory address]] 0, though that may be the case in practice. Most operating systems map the null pointer's address such that accessing it causes a segmentation fault. This behavior is not guaranteed by the C standard. Dereferencing a null pointer is [[undefined behavior]] in C, and a conforming implementation is allowed to assume that any pointer that is dereferenced is not null. <syntaxhighlight lang=c> int *ptr = NULL; printf("%d", *ptr); </syntaxhighlight> This sample code creates a [[null pointer]], and then tries to access its value (read the value). Doing so causes a segmentation fault at runtime on many operating systems. Dereferencing a null pointer and then assigning to it (writing a value to a non-existent target) also usually causes a segmentation fault: <syntaxhighlight lang=c> int *ptr = NULL; *ptr = 1; </syntaxhighlight> The following code includes a null pointer dereference, but when compiled will often not result in a segmentation fault, as the value is unused and thus the dereference will often be optimized away by [[dead code elimination]]: <syntaxhighlight lang=c> int *ptr = NULL; *ptr; </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)