+ 2

What's the difference between this {MyClass obj; MyClass *ptr = &obj;} and this {Myclass *ptr=new Myclass}?....

C++ question

2nd Sep 2022, 10:30 AM
Emediong Ekoh
Emediong Ekoh - avatar
1 ответ
+ 2
*ptr = &obj Here the pointer holds the address of an object allocated on the stack. You can also think of this as some sort of alias for your variable *ptr = new Myclass Here the pointer holds the address of an object allocated on the heap
2nd Sep 2022, 1:36 PM
giugiu
giugiu - avatar