Your example is roughly correct.
test* pd = new test(2);
The new keyword will make the compiler allocate memory on the heap for a new test object. It is equivalent to calling malloc(size) in the C language. In languages (like C and C++) without an implicit garbage collector, you are then responsible for deleting the object later.
In some short-run programs you can get away with not deleting the object, since the memory allocated by the process should be freed when your process exits in a modern machine. But that's really inelegant and should not be your habit.
It is also important not to think of test*pd = new test(2);
as storing a test object in the *pd pointer. The pointer is only pointing to it, and you can make the pointer point to other things later. The pointer has nothing to do with the new test object except that right now it happens to be pointing at it.
test ob(2);
Here, because you did not use the new keyword or otherwise allocate memory on the heap, the compiler is responsible for allocating the memory for the object--and for deleting it or forgetting about it when it falls out of scope. The stack is an ordinary way to do that, but I believe the method is technically compiler-dependent and there might be some cases where particular compilers stored the variable elsewhere.