If a and b are pointers, does this
A) Allocate memory once for b and also store address in a
B) Allocate memory twice, once for a and once for b
If a and b are pointers, does this
A) Allocate memory once for b and also store address in a
B) Allocate memory twice, once for a and once for b
There is only one new, so obviously a c is dynamically allocated once and the address stored in both a and b.
a = b = new c creates (allocates) one object of type c, then assigns the pointer to b, and then assigns the same pointer to a.
You should never write code like that as this doesn't mean the same, and the way that statement is written will often degenerate into this:
int* a = b = new c();
The assignment operator binds left, which means
a = b = new c;
is the same as
a = (b = new c);
or
a.operator=(b.operator=(c.operator new()));
What would be the point of such code??? One pointer is enough imo...
Depends on the algorithm.
There are many that require two pointers, one that will always be there and another that gets modified. In this case they are initializing both pointers at once.