not able to understand code

here is the code I am unable to understand,

1
2
3
4
5
6
const int size=2;
int main()
{
item *p=new item[size];
item *d=p;
}


can anyone please explain what is trying to do with pointer? Item is class name here.
Last edited on
A pointer is a variable that, like all variables, stores a value. The value of a pointer is a memory address. A value can be copied from one variable to an another.

1
2
3
4
5
int main()
{
  int foo = 42;
  int bar = foo;
}

At the end of this program the variable 'bar' has value 42.

What does my program try to do with integers? Nothing, except illustrate a point for educational purposes.

What does your program try to do with pointers? Nothing?
item* p points to the first element of the new array created on the heap.

item* d
is a copy of the previous pointer.

In short, they both point to the same memory location.
Last edited on
Topic archived. No new replies allowed.