Is the NULL pointer same as an uninitialized pointer?

Hi,

Is the NULL pointer same as an uninitialized pointer?

Thanks
No.
Could you give me an example?

Is it NULL pointer?

int *p = NULL;
and is it uninitialized pointer?

int *p;
An uninitialised pointer can have any value - whatever value happens to be in memory at which it is defined. The NULL (or nullptr in C++) is a pointer initialised to a known value. It's the same as having an uninitialised variable.
some compilers zero uninitialized memory in debug mode. If yours does this and you are in debug mode, it may seem they are the same, but you must not rely on this.
side note, most coders consider it good practice to initialize everything. It isn't necessary for c++, but it helps avoid obscure bugs and helps when debugging to see things go wrong.
Is it NULL pointer?

int *p = NULL;


Yes - but in C++ it should be

int *p = nullptr;

and is it uninitialized pointer?

int *p;


Yes. The value of p could be anything.
Topic archived. No new replies allowed.