[C++] Understanding Pointers and Their Useage 03-13-2014, 08:59 PM
#1
Hello HC 
Today i introduce .. POINTERS!
As i have stated in another thread A pointer is just an address to a location in memory. Depending on the architecture the address is usually 32 or 64 bits. A pointer itself is just two instructions that add two 16 bit integers based on high and low bitvalues.
But to help you better understand them here is a tutorial for you
One of the most powerful tools available to a C++ programmer is the pointer. Pointers provide the capability to manipulate computer memory directly. That power comes at a price. Pointers are one of the most difficult aspects of C++ for many beginners to learn.
A variable is an object that hold's a value. A integer variable holds a number. A character variable holds a letter. A pointer is a variable that holds a memory address.
Okay, so what is a memory address ? To fully understand this, you must know a little about computer memory. Computer memory is where variable values are stored. By convention, computer memory is divided into sequentially numbered memory locations. Each of these locations is a memory address
Every variable of every type is located at a unique address in memory. This next diagram i made shows a schematic representation of the storage of a unsigned long integer variable ' theAge ':
![[Image: 7u4dH.jpg]](http://puu.sh/7u4dH.jpg)
Different computers number the memory using different complex schemes. Usually, programmers don't need to know the particular address of any given variable because the compiler your using handles the details. If you want this information, you can use the address of operators & which is illustrated in this example
Address produces output such as the following:
![[Image: 7u4fx.png]](http://puu.sh/7u4fx.png)
the actual address of each pointer will differ because each computer will store variables at different addresses, depending on what else is in the memory and how much memory is available.
When a pointer is allocated, the compiler assigns enough memory to hold an address in your hardware and operating system environment. The size of a pointer might or might not be the same size as an integer, so be sure not to make any assumptions
I Hope this tutorial gives you a basic idea of how pointers work
thanks for reading

Today i introduce .. POINTERS!
As i have stated in another thread A pointer is just an address to a location in memory. Depending on the architecture the address is usually 32 or 64 bits. A pointer itself is just two instructions that add two 16 bit integers based on high and low bitvalues.
But to help you better understand them here is a tutorial for you

One of the most powerful tools available to a C++ programmer is the pointer. Pointers provide the capability to manipulate computer memory directly. That power comes at a price. Pointers are one of the most difficult aspects of C++ for many beginners to learn.
A variable is an object that hold's a value. A integer variable holds a number. A character variable holds a letter. A pointer is a variable that holds a memory address.
Okay, so what is a memory address ? To fully understand this, you must know a little about computer memory. Computer memory is where variable values are stored. By convention, computer memory is divided into sequentially numbered memory locations. Each of these locations is a memory address
Every variable of every type is located at a unique address in memory. This next diagram i made shows a schematic representation of the storage of a unsigned long integer variable ' theAge ':
![[Image: 7u4dH.jpg]](http://puu.sh/7u4dH.jpg)
Different computers number the memory using different complex schemes. Usually, programmers don't need to know the particular address of any given variable because the compiler your using handles the details. If you want this information, you can use the address of operators & which is illustrated in this example
Code:
#include <iostream>
int main()
{
unsigned short shortVar = 5;
unsigned long longVar = 65535;
long sVar = -65535;
std::cout << "shortVar:\t" << shortVar;
std::cout << "\tThe adress of shortVar:\t" << &shortVar << "\n";
std::cout << "longVar:\t" << longVar;
std::cout << "\tThe adress of longVar:\t" << &longVar << "\n";
std::cout << "sVar:\t" << sVar;
std::cout << "\tThe adress of sVar:\t" << &sVar << "\n";
return 0;
}![[Image: 7u4fx.png]](http://puu.sh/7u4fx.png)
the actual address of each pointer will differ because each computer will store variables at different addresses, depending on what else is in the memory and how much memory is available.
When a pointer is allocated, the compiler assigns enough memory to hold an address in your hardware and operating system environment. The size of a pointer might or might not be the same size as an integer, so be sure not to make any assumptions
I Hope this tutorial gives you a basic idea of how pointers work
thanks for reading
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)
![[Image: OilyCostlyEwe.gif]](http://fat.gfycat.com/OilyCostlyEwe.gif)

if you create compilers like i have you learn that because lexical analysis especially when it comes to parsing lexical tokens specifies everything in the syntax as an object, but other than that thank you for your feedback