dynamic memory question
Jan 27, 2017 at 11:14pm
Hi guys I have a short question,I'm just wondering how come when you set a pointer to = data in dynamic memory how come you don't use &?
for example
1 2 3 4 5 6
|
int a = 6;
int *b = &a; // LEGAL
int *b = a; // NOT LEGAL
|
well how come you don't need to put the & when using the keyword new?
for example
1 2 3 4 5
|
int *a;
a = new int[2]; // LEGAL
a = new &int[2] // NOT LEGAL
|
thanks
Jan 27, 2017 at 11:20pm
new int[2] returns a pointer to the first int in the newly created array.
Jan 27, 2017 at 11:23pm
but how come you don't declare it with the address of operator?
Jan 27, 2017 at 11:27pm
Why would you?
Topic archived. No new replies allowed.