foobar is a local variable that goes out of scope at the end of a block.
*foobar - dynamically distributed object with a manual lifetime. Since he does not have the time covered by life, the question does not make sense - he has no opportunity from which he can go. Its service life is manually controlled, and the object lives until you become its delete .
Your question is dangerously burdened by prejudice and prejudice. It is best to approach C ++ with a clean mind and an open attitude. Only in this way will you be able to fully appreciate the language miracles.
Here's a clean and open approach: Think about 1) storage classes (automatic, static, dynamic), 2) the lifetime of the object (beveled, permanent, manual), 3) the semantics object (value (copies) versus reference (aliases)), 4 ) RAII and single-user responsibility classes. Clear your mind a) stack / heap , b) pointers , c) new / delete , d) destructors / copy constructors / assignment operators .
source share