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!
===Pass-by-address using pointers=== Pointers can be used to pass variables by their address, allowing their value to be changed. For example, consider the following [[C (programming language)|C]] code: <syntaxhighlight lang="C"> /* a copy of the int n can be changed within the function without affecting the calling code */ void passByValue(int n) { n = 12; } /* a pointer m is passed instead. No copy of the value pointed to by m is created */ void passByAddress(int *m) { *m = 14; } int main(void) { int x = 3; /* pass a copy of x's value as the argument */ passByValue(x); // the value was changed inside the function, but x is still 3 from here on /* pass x's address as the argument */ passByAddress(&x); // x was actually changed by the function and is now equal to 14 here return 0; } </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)