pointer
Variable is used to store value
Pointer is used to store addresss of value
pointer
#include
// by using increment sign we know whole array
int main()
{
using namespace std;
int ar[] = { 1,2,3,4,5,6,7,8,9,10 };
for (int m : ar)
{
cout << m << endl;
}
return 0;
}
pointer
As discussed earlier, 'p' is a pointer to 'a'. Since 'a' has a value of 10, so '*p' is 10. 'p' stores the address of a. So the output p = 0xffff377c implies that 0xffff377c is the address of 'a'. '&p' represents the address of 'p' which is 0xffff3778. Now, '*&p' is the value of '&p' and the value of '&p' is the address of 'a'. So, it is 0xffff377c.
pointer
p = 0xffff377c
*p = 10
&p = 0xffff3778
*&p = 0xffff377c
pointer
#include
using namespace std;
int main()
{
int* p;
p = new int;
if (p)
{
cout << "success";
}
return 0;
}
|