I have struct:
struct stek
{
char value;
struct stek *next;
};
Why i can init this like this:
stek *p = 0;
What this mean? Why zero?
I have struct:
struct stek
{
char value;
struct stek *next;
};
Why i can init this like this:
stek *p = 0;
What this mean? Why zero?
tldr; Because 0 is a valid memory address.
Since pointers point to memory locations, the expression is valid and p
points to memory address 0
Here 0
means NULL
. In prior C++11, 0
can be used as NULL
which is pretty ambiguous sometimes. Currently C++ has nullptr
which makes more sense.
Read more about difference between NULL and nullptr.