0

can any explain example of pointer?

22nd Jul 2016, 2:54 PM
krishna desai
2 Answers
0
a pointer allows us to point back to a memory address int a=45;//regular integer a that has a value of 45 int* p=&a;//integer pointer p that has the value of a's memory address so far we've made int a with a value of 45, and an integer pointer p with a value of a's memory location. so if we say something like *p=34; this is saying go to the memory address stored in p, in our case a, and set that value of 34. so if we now do something like cout << a; 34 is printed to the screen instead of 45
22nd Jul 2016, 4:41 PM
destro
0
#include<iostream> using namespace std; { int a = 5; // here a holds the integer value that is 5 int *p; // p is a pointer to an integer p=&a // here p is holding the memory address of a therefore ampersand (address of ) is used cout<<a; // value of a will be printed i.e 5 cout<<p; // address of a will be printed cout<<*p; // again value of a will be printed return 0; }
23rd Jul 2016, 5:12 AM
Karan Luther
Karan Luther - avatar