User Tools

Site Tools


cplusplus:pointers_1

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_1 [2018/02/24 20:48] – [Pointer syntax basics] mithatcplusplus:pointers_1 [2018/02/24 20:51] – [Pointer syntax basics] mithat
Line 50: Line 50:
 {{ :cplusplus:ptr02.png?nolink |}} {{ :cplusplus:ptr02.png?nolink |}}
  
-In this diagram, the //value// of the pointer ''countPtr'' is the arrow that points to the integer  ''count''.+In this diagram, the //value// of the pointer ''countPtr'' is the box the arrow points to (i.e., the integer  ''count'').
  
 Just as the value of a normal variable can change, the value of a pointer can change as well. Let’s say in addition to the variable ''count'' we also have a variable ''num'' that holds the value 2. If we change the value of ''countPtr'' to point to ''num'', the diagram would now look like: Just as the value of a normal variable can change, the value of a pointer can change as well. Let’s say in addition to the variable ''count'' we also have a variable ''num'' that holds the value 2. If we change the value of ''countPtr'' to point to ''num'', the diagram would now look like:
Line 133: Line 133:
 Pointer variables in C++ are not automatically initialized. This means that a pointer variable declaration along the lines of Pointer variables in C++ are not automatically initialized. This means that a pointer variable declaration along the lines of
 <code cpp>double *myPtr;</code> <code cpp>double *myPtr;</code>
-leaves the pointer pointing to an arbitrary memory location. This is dangerous because poking your fingers into arbitrary memory locations is a good way to corrupt your program's memory.+leaves the pointer pointing to an arbitrary memory location. This is dangerous because poking your fingers into arbitrary memory locations is a good way to corrupt your program's memory or create other headaches.
  
 Pointer variables can be initialized when declared. It is good programming practice to always initialize pointers so they do not accidentally point to unknown memory locations. The code below initializes the value of the pointer variable in the declaration: Pointer variables can be initialized when declared. It is good programming practice to always initialize pointers so they do not accidentally point to unknown memory locations. The code below initializes the value of the pointer variable in the declaration:
cplusplus/pointers_1.txt · Last modified: 2019/03/28 16:24 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki