what is the different between 'new()' int and 'int *p' [closed]

int *p;
*p = 10;

Dereferencing an uninitialized pointer has undefined behaviour.

int *q = new() int(10);

This is syntactically incorrect, as the following compiler message reveals:

main.cpp:7:18: error: expected expression-list or type-id
     int *q = new() int(10);
                  ^

So, to answer the question…

Can int *q = new() int(10) be replaced by int *q; *q = 10 anywhere?

No. Neither may be used anywhere in a program.

Leave a Comment