Download - Pointer in c++ part1
![Page 1: Pointer in c++ part1](https://reader034.vdocument.in/reader034/viewer/2022051514/549b0c98b479591f098b467e/html5/thumbnails/1.jpg)
Author – Subhasis Nayak
![Page 2: Pointer in c++ part1](https://reader034.vdocument.in/reader034/viewer/2022051514/549b0c98b479591f098b467e/html5/thumbnails/2.jpg)
A pointer is a variable that holds amemory address. That’s it.
This is what the difference in betweenvariable and pointer.◦ Pointer holds the address
◦ Variable holds the value.
![Page 3: Pointer in c++ part1](https://reader034.vdocument.in/reader034/viewer/2022051514/549b0c98b479591f098b467e/html5/thumbnails/3.jpg)
Computer memory is divided intosequentially numbered memory locations.Each variable is located at a unique locationin memory, known as its address.
Memory representation
![Page 4: Pointer in c++ part1](https://reader034.vdocument.in/reader034/viewer/2022051514/549b0c98b479591f098b467e/html5/thumbnails/4.jpg)
The capability to use pointers andmanipulate memory at a low levelis one of the factors that makesC++ the language of choice forembedded and real-timeapplications.
![Page 5: Pointer in c++ part1](https://reader034.vdocument.in/reader034/viewer/2022051514/549b0c98b479591f098b467e/html5/thumbnails/5.jpg)
Different computers number this memoryusing different complex schemes.
We must happy, as a programmer, We don’tneed to know the particular address of anygiven variable because the compiler handlesthe details.
If we want this information, though, you canuse the address-of operator (&), whichreturns the address of an object in memory.
![Page 6: Pointer in c++ part1](https://reader034.vdocument.in/reader034/viewer/2022051514/549b0c98b479591f098b467e/html5/thumbnails/6.jpg)
![Page 7: Pointer in c++ part1](https://reader034.vdocument.in/reader034/viewer/2022051514/549b0c98b479591f098b467e/html5/thumbnails/7.jpg)
It is so simple to declare a pointer. We needthe type of the pointer
Next the name of the pointer.
When we declare a pointer variable such aspointer, the compiler sets aside enoughmemory to hold an address
int *pointer;
![Page 8: Pointer in c++ part1](https://reader034.vdocument.in/reader034/viewer/2022051514/549b0c98b479591f098b467e/html5/thumbnails/8.jpg)
A pointer that is not initialized is called a wildpointer because you have no idea what it ispointing to.
If you want to initialize you can as like we dofor variable. int *intPointer = 0;
A pointer whose value is zero is called a nullpointer.
All pointers, when they are created, should beinitialized to something.
![Page 9: Pointer in c++ part1](https://reader034.vdocument.in/reader034/viewer/2022051514/549b0c98b479591f098b467e/html5/thumbnails/9.jpg)
Every variable has an address. Even withoutknowing the specific address, you can store avariable’s address in a pointer.
Declaring pointer Passing address
![Page 10: Pointer in c++ part1](https://reader034.vdocument.in/reader034/viewer/2022051514/549b0c98b479591f098b467e/html5/thumbnails/10.jpg)
Holds the address
Holds the value
![Page 11: Pointer in c++ part1](https://reader034.vdocument.in/reader034/viewer/2022051514/549b0c98b479591f098b467e/html5/thumbnails/11.jpg)
Type must be same to the variable whoseaddress is going to pass to the pointer.
When you want to pass the address of thevariable use (&) before the variable name.
When you want to pass the value use (*)before the pointer.