User Tools

Site Tools


cplusplus:pointers_2

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 [2016/03/05 22:21] – [Pointers as function parameters] mithatcplusplus:pointers_2 [2016/03/05 22:27] – [Calling functions by reference] mithat
Line 89: Line 89:
 void cubeByReference(int *nPtr) void cubeByReference(int *nPtr)
 { {
-    *nPtr = *nPtr * *nPtr * *nPtr;+    *nPtr = (*nPtr(*nPtr(*nPtr)// parenthesis for readability
 } }
 </file> </file>
 +
 +<WRAP center round tip 90%>
 +I (and many other programmers) feel this is a much better way of implementing call by reference because the syntax in the function invocation (e.g., ''cubeByReference(&number))'' makes it clear that a pointer is involved---which is good tip off that call by reference is being used.
 +</WRAP>
  
 ===== The const qualifier and pointers ===== ===== The const qualifier and pointers =====
cplusplus/pointers_2.txt · Last modified: 2019/03/28 16:55 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki