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
cplusplus:pointers_2 [2019/03/11 19:53] – [Pointer to constant data] mithatcplusplus:pointers_2 [2019/03/28 16:55] (current) mithat
Line 54: Line 54:
 ===== Calling functions by reference ===== ===== Calling functions by reference =====
  
-Pointers can be used to implement //call-by-reference// in functions. The ''*'' operator is used to alias a variable inside of function.  +Pointers can be used to implement //passing by reference// in functions. The ''*'' operator is used to alias a variable inside of function.  
  
 <code cpp> <code cpp>
Line 63: Line 63:
 </code> </code>
  
-In the function above, ''*number'' is used as an alias for the variable passed in. Strictly speaking, the passing mechanism is //call-by-value// because the argument that is passed into the function (an address) is copied to the formal pointer parameter ''number''. However, dereferencing ''number'' acts as an alias to whatever is passed in.+In the function above, ''*number'' is used as an alias for the variable passed in. Strictly speaking, the passing mechanism is //pass by value// because the argument that is passed into the function (an address) is copied to the formal pointer parameter ''number''. However, dereferencing ''number'' acts as an alias to whatever is passed in.
  
  
 <file cpp cube-by-reference.cpp> <file cpp cube-by-reference.cpp>
-/** Cube a variable using call-by-reference with a pointer. */+/** Cube a variable using pass by reference with a pointer. */
 #include <iostream> #include <iostream>
 using namespace std; using namespace std;
Line 89: Line 89:
  
 <WRAP center tip 90%> <WRAP center tip 90%>
-I feel pointers are much better than reference parameters for 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 indication that call by reference is being used.+I feel pointers are much better than reference parameters for implementing pass by  reference because the syntax in the function invocation (e.g., ''cubeByReference(&number))'' makes it clear that a pointer is involved --- which is good indication that pass by  reference is being used.
 </WRAP> </WRAP>
  
cplusplus/pointers_2.1552334008.txt.gz · Last modified: 2019/03/11 19:53 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki