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
Pointer (computer programming)
(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!
====Dangling pointer==== {{Main|Dangling pointer}} A '''dangling pointer''' is a pointer that does not point to a valid object and consequently may make a program crash or behave oddly. In the [[Pascal (programming language)|Pascal]] or [[C (programming language)|C programming languages]], pointers that are not specifically initialized may point to unpredictable addresses in memory. The following example code shows a dangling pointer: <syntaxhighlight lang="C"> int func(void) { char *p1 = malloc(sizeof(char)); /* (undefined) value of some place on the heap */ char *p2; /* dangling (uninitialized) pointer */ *p1 = 'a'; /* This is OK, assuming malloc() has not returned NULL. */ *p2 = 'b'; /* This invokes undefined behavior */ } </syntaxhighlight> Here, <code>p2</code> may point to anywhere in memory, so performing the assignment <code>*p2 = 'b';</code> can corrupt an unknown area of memory or trigger a [[segmentation fault]].
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)