-2

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?

Admiral Land
  • 2,136
  • 7
  • 38
  • 72

2 Answers2

2

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

smac89
  • 32,960
  • 13
  • 112
  • 152
1

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.

Kaidul
  • 14,691
  • 13
  • 77
  • 145