Hello, I'm new to C++ with a fair experience in java.

I would like to know the difference between

Ob o* = new Ob();

and

Ob o = new Ob();

I know the first allocates a block of memory and creates a pointer which keeps the address of this block.

What about the second object initialization?

Thank you

The second is invalid. Only a pointer to can use the new operator. Here is a little breakdown for you.

int foo = 10;  // normal assignment;
int *fooPointer = new int;
*fooPointer = foo;  // now fooPointer is a pointer to an int that holds the value of 10
int & fooReference = foo;  // reference.  now anything that happens to fooReference happens to foo.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.