Question about pointers
I watched this video and I have a question(it´s not about the context in video, just a general question about pointers) . At timemark 5:05 it says:
int *p = new int;
*p = 5;
p = new int(10);
Line 1 he´s creating the pointer p and reserves memory. In line 2 he´s pointing to 5. So far so good. In line 3 he´s pointing to another, new reserved memory with the value of 10.
Why isnt it possible to write:
int *p = new int;
*p = 5;
*p = new int(10);
Or, in other words, when do I need to write a "*" before the pointer and when not?
Posted Feb 25, 2016, 12:35 AM UTC
29