cplusplus:pointers_2_slides
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
cplusplus:pointers_2_slides [2021/10/19 19:34] – [Calling functions by reference] mithat | cplusplus:pointers_2_slides [2021/10/19 19:42] – [Constant pointers] mithat | ||
---|---|---|---|
Line 63: | Line 63: | ||
* Pointers can be used to implement //pass by reference// in functions. | * Pointers can be used to implement //pass by reference// in functions. | ||
* The '' | * The '' | ||
- | | + | * Strictly speaking, the passing mechanism is //call by value//. But functionality is pass by reference. |
- | | + | * Syntax |
- | * The syntax | + | |
===== Calling functions by reference ===== | ===== Calling functions by reference ===== | ||
Line 86: | Line 85: | ||
void cubeByReference(int *nPtr) | void cubeByReference(int *nPtr) | ||
{ | { | ||
+ | // *nptr'' | ||
*nPtr = (*nPtr) * (*nPtr) * (*nPtr); // parenthesis for readability | *nPtr = (*nPtr) * (*nPtr) * (*nPtr); // parenthesis for readability | ||
} | } | ||
Line 104: | Line 104: | ||
* A **constant pointer** is a pointer whose value cannot change. | * A **constant pointer** is a pointer whose value cannot change. | ||
- | * Constant pointers store a memory location that cannot be changed. | + | * Constant pointers |
* Must be initialized when declared. | * Must be initialized when declared. | ||
- | * Use the '' | + | * '' |
<code c++> | <code c++> |
cplusplus/pointers_2_slides.txt · Last modified: 2021/10/19 19:46 by mithat