79297064

Date: 2024-12-20 11:28:55
Score: 0.5
Natty:
Report link

A pointer is what it says: a pointer to what is ultimately a physical location in memory. This does not mean the ultimate location must be specified when the pointer is defined, but before it is used in a program to point to something the target location must be defined, possibly through one or more other pointers but ultimately an actual memory location. A pointer may point to a pointer, as many times as you like but ultimately the result must point to a real memory location and data type to be useful. An example of a pointer being particularly useful is when you have a common routine working on passed parameters. The length of the parameters does not matter, the common routine does not need to allocate memory to work, as the pointer has the ultimate definition of its value, a string, for example, and the routine does not need to allocate space for the maximum length of the parameter value. In your examples, whether you define pc itself or a pointer to pc depends on the requirements of the program and your preferred programming approach, but before the pointer can be used effectively its ultimate value in memory must be defined. In tricky, but powerful, situations I sometimes find it is more useful to actually assign memory locations for pointers and variables on a piece of paper and put in actual figures to understand what is going on.

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: WarwickW