Is this code correct in terms of the memory management?

#include <exception>

struct A {
  void Foo() { throw std::exception(); }
};

void Test() {
  A *a = new A();
  a->Foo();
  delete a;
}
Explanation
No, because in the Test() function there is a leak of memory, allocated for a.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
C++ quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes