pointerincpart1-100604094615-phpapp01
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Author – Subhasis Nayak
A pointer is a variable that holds a<br />
memory address. That’s it.<br />
This is what the difference in between<br />
variable and pointer.<br />
◦ Pointer holds the address<br />
◦ Variable holds the value.
Computer memory is divided into<br />
sequentially numbered memory locations.<br />
Each variable is located at a unique location<br />
in memory, known as its address.<br />
Memory representation
The capability to use pointers and<br />
manipulate memory at a low level<br />
is one of the factors that makes<br />
C++ the language of choice for<br />
embedded and real-time<br />
applications.
Different computers number this memory<br />
using different complex schemes.<br />
We must happy, as a programmer, We don’t<br />
need to know the particular address of any<br />
given variable because the compiler handles<br />
the details.<br />
If we want this information, though, you can<br />
use the address-of operator (&), which<br />
returns the address of an object in memory.
It is so simple to declare a pointer.<br />
the type of the pointer<br />
Next the name of the pointer.<br />
We need<br />
When we declare a pointer variable such as<br />
pointer, the compiler sets aside enough<br />
memory to hold an address<br />
int *pointer;
A pointer that is not initialized is called a wild<br />
pointer because you have no idea what it is<br />
pointing to.<br />
If you want to initialize you can as like we do<br />
for variable. int *intPointer = 0;<br />
A pointer whose value is zero is called a null<br />
pointer.<br />
All pointers, when they are created, should be<br />
initialized to something.
Every variable has an address. Even without<br />
knowing the specific address, you can store a<br />
variable’s address in a pointer.<br />
Declaring pointer<br />
Passing address
Holds the value<br />
Holds the address
Type must be same to the variable whose<br />
address is going to pass to the pointer.<br />
When you want to pass the address of the<br />
variable use (&) before the variable name.<br />
When you want to pass the value use (*)<br />
before the pointer.