0
Pointers can only hold address?
how is this possible? int c; //declaration int* pc = new c; // pointer pointing towards an address in heap *pc=c; ( why not *pc= &c;)
2 odpowiedzi
+ 8
*pc = c;
assigns the value of c to the value pointed by the address stored in pc.
*pc = &c;
is a common mistake made by beginners. (* should not be used here)
pc = &c;
assigns address of variable c to pointer pc.
+ 2
When declaring your pointer, you can remove the new and it would be valid as well:
int c;
int* p_c = c;