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
cplusplus:pointers_2_slides [2021/10/19 19:40] – [Calling functions by reference] mithatcplusplus:pointers_2_slides [2021/10/19 19:46] (current) – [Constant pointer to constant data] mithat
Line 28: Line 28:
   * Arguments can be anything that can be assigned to a pointer (i.e., addresses or pointers).   * Arguments can be anything that can be assigned to a pointer (i.e., addresses or pointers).
  
-===== Pointers as function parameters =====+===== Example =====
 <file cpp function-with-pointer.cpp> <file cpp function-with-pointer.cpp>
 /** Demonstrates how to pass pointers to functions. */ /** Demonstrates how to pass pointers to functions. */
Line 66: Line 66:
   * 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.   * 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 =====+===== Example =====
 <file cpp cube-by-reference.cpp> <file cpp cube-by-reference.cpp>
 /** Cube a variable using pass by reference with a pointer. */ /** Cube a variable using pass by reference with a pointer. */
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 //store a memory location that cannot be changed//.
   * Must be initialized when declared.   * Must be initialized when declared.
-  * Use the ''const'' keyword between the ''*'' and the name of the pointer:+  * ''const'' keyword goes between the ''*'' and the name of the pointer:
  
 <code c++> <code c++>
 int *const myPtr = &x;  // constant pointer to a (non-constant) int int *const myPtr = &x;  // constant pointer to a (non-constant) int
 +                        // myPtr will always point to x
 </code> </code>
  
Line 139: Line 140:
   * A **pointer to constant data** cannot change the value of what it's pointing to.   * A **pointer to constant data** cannot change the value of what it's pointing to.
   * Can point to different things.   * Can point to different things.
-  * Use the ''const'' keyword to qualify the type being pointed to.+  * ''const'' keyword qualifies the type being pointed to.
  
 <code cpp> <code cpp>
Line 151: Line 152:
 ===== Constant pointer to constant data ===== ===== Constant pointer to constant data =====
  
-  * **Constant pointer to constant data** cannot change either "what it is pointing to" nor the value of "what it is pointing to."+  * **Constant pointer to constant data** cannot change either "what it is pointing to" or the value of "what it is pointing to."
  
 <code cpp> <code cpp>
cplusplus/pointers_2_slides.1634672437.txt.gz · Last modified: 2021/10/19 19:40 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki