pointers question

hi guys just a quick question on pointers and trying to understand them in more depth

so I create a pointer py then I create a pointer that points to a pinter ppx then I assign the value of ppx to the address of py BUT now this is the part I don't understand *ppx = new int;


how can I use *ppx when I never created a pointer called *ppx? why and how can I set *ppx which I never declared to a random int value from the free store?

1
2
3

*ppx = new int;


and what exactly is this statement doing ^^


1
2
3
4
5
6
7
 
     int *py;
     int **ppx;
     ppx = &py;
    *ppx = new int;
    cout << ppx << endl;
    cout << **ppx << endl;


thanks in advance,

Adam
Last edited on
Hi,
You can say that a pointer is just some kind of a special integer variable that solely stores the memory address to another variable. And that's why a pointer variable can be called a "memory address pointer" variable.
*ppx=new int; simply means dereference ppx and allocate an int memory space to the pointer ppx points to(which is py).
Topic archived. No new replies allowed.