User Tools

Site Tools


cplusplus:pointers_2_slides

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
cplusplus:pointers_2_slides [2021/10/19 19:36] – [Calling functions by reference] mithatcplusplus:pointers_2_slides [2021/10/19 19:40] – [Calling functions by reference] mithat
Line 64: Line 64:
   * The ''*'' operator is used to alias a variable inside of function.     * The ''*'' operator is used to alias a variable inside of function.  
   * Strictly speaking, the passing mechanism is //call by value//. But functionality is pass by reference.   * Strictly speaking, the passing mechanism is //call by value//. But functionality is pass by reference.
-  * The syntax in the function invocation (e.g., ''cubeByReference(&number))'' makes it clear that a pointer is involved --- which is good indication that call by reference is being used.+  * Syntax in function invocation (e.g., ''cubeByReference(&number))'' makes clear that a pointer is involved --- good indication that call by reference is used in the function.
  
 ===== Calling functions by reference ===== ===== Calling functions by reference =====
Line 85: Line 85:
 void cubeByReference(int *nPtr) void cubeByReference(int *nPtr)
 { {
 +    // *nptr'' is an alias for the variable passed in.
     *nPtr = (*nPtr) * (*nPtr) * (*nPtr); // parenthesis for readability     *nPtr = (*nPtr) * (*nPtr) * (*nPtr); // parenthesis for readability
 } }
cplusplus/pointers_2_slides.txt · Last modified: 2021/10/19 19:46 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki