User Tools

Site Tools


cplusplus:pointers_1_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
Last revisionBoth sides next revision
cplusplus:pointers_1_slides [2021/10/19 19:20] – [Assignment] mithatcplusplus:pointers_1_slides [2021/10/19 19:28] – [Pointer operators] mithat
Line 61: Line 61:
 ===== Pointer syntax basics ===== ===== Pointer syntax basics =====
  
-===== Declaration =====+===== Pointer declaration =====
   * ''*'' character is used to indicate pointer variables in declarations and function parameter lists.   * ''*'' character is used to indicate pointer variables in declarations and function parameter lists.
   * Type of data being pointed to must also be indicated.   * Type of data being pointed to must also be indicated.
Line 78: Line 78:
 </code> </code>
  
-===== Declaration =====+===== Pointer declaration =====
  
   * You can declare more than one pointer variable at a time:   * You can declare more than one pointer variable at a time:
Line 100: Line 100:
   * Most environments show base addresses as [[http://www.cplusplus.com/doc/hex/|hexadecimal]] numbers.   * Most environments show base addresses as [[http://www.cplusplus.com/doc/hex/|hexadecimal]] numbers.
  
-===== Assignment =====+===== Pointer assignment =====
  
   *  Declare an integer variable ''y'' and a pointer variable ''myPtr'' set to store the address of ("point to") ''y''.   *  Declare an integer variable ''y'' and a pointer variable ''myPtr'' set to store the address of ("point to") ''y''.
Line 111: Line 111:
 {{:cplusplus:ptr04a.png?nolink|}} {{:cplusplus:ptr04a.png?nolink|}}
  
-===== Assignment =====+===== Pointer assignment =====
  
   *  Declare an integer variable ''y'' and a pointer variable ''myPtr'' set to store the address of ("point to") ''y''.   *  Declare an integer variable ''y'' and a pointer variable ''myPtr'' set to store the address of ("point to") ''y''.
Line 143: Line 143:
 </code> </code>
  
-===== Initialization =====+===== Pinter initialization =====
   * Local pointer variables in C++ are not automatically initialized.    * Local pointer variables in C++ are not automatically initialized. 
   * Uninitialized pointers point to arbitrary memory. //Very dangerous.//   * Uninitialized pointers point to arbitrary memory. //Very dangerous.//
Line 165: Line 165:
   * ''nullptr'' and ''NULL'' have an integer value of ''0'', so sometimes programmers use ''0'' or '''\0'''.   * ''nullptr'' and ''NULL'' have an integer value of ''0'', so sometimes programmers use ''0'' or '''\0'''.
  
-===== Pointer operators =====+===== Operators for pointers =====
  
-  *  **address operator** ''&'' (above). +  *  **address operator** ''&'' (already covered). 
-  *  **indirection** or **dereferencing operator** ''*'' (below).+  *  **indirection** or **dereferencing operator** ''*'' (covered next).
  
 ===== Indirection/dereferencing operator ===== ===== Indirection/dereferencing operator =====
cplusplus/pointers_1_slides.txt · Last modified: 2021/10/19 19:29 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki