The simple answer is NO, YOU CAN'T SUBTRACT A NULL FROM ANOTHER NULL.
I think you misunderstood this definition:
NULL is clearly defined as: An integer constant expression with the
value 0, or such an expression cast to type void, is called a null
pointer constant. So I used to think that we could subtract one 0 from
another 0.
Now, As for now let's take GOOGLE's Definition of NULL
Null means having no value; in other words null is zero, like if you
put so little sugar in your coffee that it's practically null. Null
also means invalid. From the Latin nullus,
meaning "not any," poor, powerless null is not actually there at all.
Clearly, it states that null has no value. Think of it as you are trying to subtract nothing from nothing.
Now let's take it in other words, null is zero (if and only if defined value) you can subtract it for sure (but not you can do something like char *ab = NULL, char *aa= NULL and then performing subtraction like ab-aa is still illegal)
But no one can actually predict the value for null so, when you are unable to get the value you are not able to perform any operation(like subtraction, addition, etc.) on that.
void *
, is called a null pointer constant. So I used to think that we could subtract one 0 from another 0... – IsaacNULL
is defined as an integer constant expression you can subtractNULL
fromNULL
, but not that is not portable because it might not be (and usually isn't) defined as an integer constant expression. – InterurbanNULL
is defined as an integer 0, then after assigningchar *a = NULL; char *b = NULL;
, then the subtractiona - b
is still illegal. – Interurbanvoid *
pointers to elements of the same array, because you cannot have an array ofvoid
. (Yes, I know GCC allows pointer arithmetic on pointers tovoid
as an extension to the C language.) – Interurbanfirst
andsecond
happen to beNULL
. (And yes, I know I'm a bit late with that observation). – Gigolo