A pointer variable is an object that can point to another object. Here int *ptr = NULL; declares ptr as a pointer object, that potentially points to an object of int.
The value initially stored into this pointer object is NULL (it is initialized to NULL, so ptr does not point to any object).
Now, ptr too resides in memory. It needs enough bytes to contain the address of the pointed-to object. So it too needs to have an address. Therefore
ptrevaluates to the address of object thatptrpoints to.&ptrevaluates to the location of theptrobject itself in memory*ptrevaluates to the value of the object thatptrpoints to, if it points to an object. If it does not point to an object, then the behaviour is undefined.
Also, %p needs a void * as the corresponding argument, therefore the proper way to print them is
printf("%p\n", (void *)ptr);
printf("%p\n", (void *)&ptr);
Answer from Antti Haapala on Stack Overflowc - Address of NULL pointer - Stack Overflow
c - What is the value of a NULL address location? - Stack Overflow
What is Null?
What does the word "null" appear in front… - Apple Community
A pointer variable is an object that can point to another object. Here int *ptr = NULL; declares ptr as a pointer object, that potentially points to an object of int.
The value initially stored into this pointer object is NULL (it is initialized to NULL, so ptr does not point to any object).
Now, ptr too resides in memory. It needs enough bytes to contain the address of the pointed-to object. So it too needs to have an address. Therefore
ptrevaluates to the address of object thatptrpoints to.&ptrevaluates to the location of theptrobject itself in memory*ptrevaluates to the value of the object thatptrpoints to, if it points to an object. If it does not point to an object, then the behaviour is undefined.
Also, %p needs a void * as the corresponding argument, therefore the proper way to print them is
printf("%p\n", (void *)ptr);
printf("%p\n", (void *)&ptr);
ptr holds the value NULL which is what you assigned.
&ptr is the address to the variable ptr which in your case is 0x7fff3415dc40
You're setting a pointer to 0 (NULL) and then adding 1 to it; then you're converting the result to an int and printing the result. The key piece of knowledge you need here is that when you increment (add 1 to) a pointer, you actually add the size of the pointed-to object -- an int pointer is advanced to point to the next int. Since int is (apparently) 4 bytes on your platform, p is incremented to point to an address 4 bytes past where it starts.
Size of the int in C is (typically) 4 bytes. So incrementing a pointer by one unit means incrementing it's value by sizeof(int).
Also, you aren't printing the value of which pointer is directing (as this would certainly crash your program) but the value of the pointer itself. You should definitely take a look at any pointers tutorial in C (or in general).
So I use C# and I often see many devs use null.
What and which kind of situation do you use this variable?
I am reading c# guide on programming book and I am on Clearing memory now and I haven't encountered null yet. Should I be worried?